Silverlight GridSplitter: simulate "snap to grid"
I am working with Silverlight 3.
I have a grid with 2 columns and with a GridSplitter between them. How do I make the Grid开发者_开发技巧Splitter snap to 5px increment when dragged?
Thank you.
My best guess is you'll have to capture the MouseLeftButtonDown event and detect dragging. If not dragging, then cancel the event. If dragging is detected, capture the start position in a class variable. In MouseMove, compare the mouse position to the start position and determine whether to increment or decrement the Grid Splitter position.
To get this to work, I think you will need to adjust the width of the left grid column programmatically based on the increment/decrement decision above.
I'll be curious to see how this goes.
The GridSplitter exposes the DragIncrement property that sets the minimum distance that a user must drag a mouse to resize rows or columns. Therefore, you could do something like:
<GridSplitter Grid.Row="1" VerticalAlignment="Bottom" HorizontalAlignment="Stretch" DragIncrement="5"/>
Edit: I just realized that you were talking about Silverlight. Looks like the DragIncrement property is only available in WPF. Sorry about your luck.
精彩评论