views:

467

answers:

2

I am working with Silverlight 3.

I have a grid with 2 columns and with a GridSplitter between them. How do I make the GridSplitter snap to 5px increment when dragged?

Thank you.

+2  A: 

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.

Joel Cochran
Thanks, Joel. What you are saying is fair and I might have to go that way. For now, though, I am waiting for some other answers before marking any as "accepted".
Ciprian Bortos
This is a pertinent answer so I am marking it as accepted. I kind of expected to have other suggestions too.
Ciprian Bortos
A: 

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.

Brent
yes, the DragIncrement property is what I want, but unfortunately in Silverlight 3 we only have a private constant with a value of 1.
Ciprian Bortos