Search code examples
c#silverlightsilverlight-3.0gridsplitter

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 GridSplitter snap to 5px increment when dragged?

Thank you.


Solution

  • 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.