1. Declare three private fields
private double scrollChange;
private double widthThreshold = 100;
private double heightThreshold = 100;
2. Add the events for gridspliter
<GridSplitter Grid.Column="1" Margin="0,7,0,0" Name="gridSplitterColumn" Style="{StaticResource gridSplitterStyleForResizeColumns}" DragDelta="gridSplitter_DragDelta" DragCompleted="gridSplitter_DragCompleted" PreviewMouseMove="gridSplitter_PreviewMouseMove" />
<GridSplitter Grid.Row="1" Name="gridSplitterForRow" Style="{StaticResource gridSplitterStyleForResizeRows}" HorizontalAlignment="Stretch" Height="7" DragDelta="gridSplitter_DragDelta" DragCompleted="gridSplitter_DragCompleted" PreviewMouseMove="gridSplitter_PreviewMouseMove" />
For how to define the style for gridSplitterStyleForResizeColumns and gridSplitterStyleForResizeRows, please refrence this articlehttp://blog.csdn.net/farawayplace613/article/details/7101587
3. Handle the events gridSplitter_DragDelta, gridSplitter_DragCompleted, gridSplitter_PreviewMouseMove
private void gridSplitter_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
{
if (sender.Equals(this.gridSplitterForRow))
{
this.scrollChange= e.VerticalChange;
}
else if (sender.Equals(this.gridSplitterColumn))
{
this.scrollChange= e.HorizontalChange;
}
}
private void gridSplitter_DragCompleted(object sender, System.Windows.Controls.Primitives.DragCompletedEventArgs e)
{
this.scrollChange = 0;
}
private void gridSplitter_PreviewMouseMove(object sender, MouseEventArgs e)
{
if (Math.Abs(this.verticalChange) > 0.1)
{
if (sender.Equals(this.gridSplitterForRow))
{
if (this.someRow.ActualHeight <= heightThreshold && this.scrollChange < 0)
{
e.Handled = true;
}
if (this.anotherRow.ActualHeight <= heightThreshold && this.scrollChange > 0)
{
e.Handled = true;
}
}
else if (sender.Equals(this.gridSplitterColumn))
{
if (this.someColumn.ActualWidth <= widthThreshold && this.scrollChange < 0)
{
e.Handled = true;
}
if (this.anotherColumn.ActualWidth <= widthThreshold && this.scrollChange > 0)
{
e.Handled = true;
}
}
}
}