I want an event ha开发者_开发技巧ndler that handles the event when the grid splitter is being moved, Im not sure if there is one, if not, I guess I can generated an event when the size of the rows are changed?
Thanks.
You could do the rows changing size, but GridSplitter itself is a Thumb and so has its own events such as DragStarted and DragCompleted. More details here.
Edit: If you make the GridSplitter focusable and allow it to be moved with the keyboard, read the answer by Benlitz for more information.
I didn't tested, but I'm pretty sure that the currently accepted answer from AresAvatar won't work if you're resizing the rows/columns using keyboard arrows (by giving the focus to the grid splitter). This is a rare but possible case that you should anticipate in your application.
When the grid splitter is moved (either by drag'n'drop or using keyboard arrows), it changes the Width
/Height
dependency properties of the ColumnDefinitions
/RowDefinitions
of the grid. You can easily register a handler on this property change:
var heightDescriptor = DependencyPropertyDescriptor.FromProperty(RowDefinition.HeightProperty, typeof(ItemsControl));
heightDescriptor.AddValueChanged(myGrid.RowDefinitions[0], HeightChanged);
(This snippet will for instance track size change in the first row of the grid).
Then you can handle resize in an handler that will work in every case.
private void HeightChanged(object sender, EventArgs e)
{
// TODO: handle row resize
}
Generally, it is really not advised to rely on the user input action (mouse dragging, keyboard inputs...) to handle a logical or visual actions/events, since there are almost always several ways to do the same actions using different inputs (mouse, keyboards, touchscreen, ease-of-use tools...).
Use DragDelta. Be aware that if you want to change the size, use as the Actual property as the current size like ActualWidth instead of Width.
精彩评论