How to stop the gridspliter when the height or width reach the thresholds

21 篇文章 0 订阅

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;
                    }
                }
            }
        }


 


 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值