![](/img/trans.png)
[英]How to support element expand/collapse and resize with WPF GridSplitter?
[英]How to make GridSplitter to “snap” into another element?
我有一個數據網格和一個網格拆分器:
拆分器在底部,數據網格在頂部,兩者之間有一些空白。
我認為,如果網格拆分器與數據網格之間的距離不超過24個或更少,那么它將可以很好地工作。 可以存檔嗎?
我用它來捕捉每個數據網格行:
private void GridSplitterDragCompleted(object sender, DragCompletedEventArgs e)
{
// We want the grid splitter to snap in grid of 24 units.
var excess = (int) FooDataGridRowDefinition.Height.Value % 24;
if (excess == 0)
return;
FooDataGridRowDefinition.Height = new GridLength(FooDataGridRowDefinition.Height.Value - excess);
}
數據網格行對我來說都是24行,我想我可以動態獲取它們,但是現在就可以了。
XAML:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" Name="FooDataGridRowDefinition" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<DataGrid Grid.Row="0" />
<GridSplitter Grid.Row="1" DragCompleted="GridSplitterDragCompleted" />
<Foo Grid.Row="2" />
</Grid>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.