在我看來,這是一個錯誤發生時,至少有一列定義設置爲像素值。如果您將列定義更改爲星號值,則一切正常。檢查你的代碼的這個修改後的版本:
<Window x:Class="Gridsplitter.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow">
<Grid>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Grid x:Name="Holdergrid" MaxWidth="{Binding RelativeSource={RelativeSource AncestorType=Window}, Path=ActualWidth}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" MinWidth="300" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="400" MinWidth="300" />
</Grid.ColumnDefinitions>
<Button Grid.Column="0" Content="{Binding RelativeSource={RelativeSource Self}, Path=ActualWidth}"></Button>
<Button Grid.Column="2" Content="{Binding RelativeSource={RelativeSource Self}, Path=ActualWidth}"></Button>
<GridSplitter Name="GridSplitterFolders" HorizontalAlignment="Center" VerticalAlignment="Stretch" Grid.Column ="1" Width ="5" ResizeBehavior="PreviousAndNext"/>
</Grid>
<StackPanel Grid.Row="1" Orientation="Horizontal">
<TextBlock Text="{Binding ElementName=Holdergrid, Path=ActualWidth, StringFormat=Actual Width: {0}}"></TextBlock>
<TextBlock Text="{Binding ElementName=Holdergrid, Path=Width, StringFormat=Width: {0}}" Margin="10 0 0 0"></TextBlock>
<TextBlock Text="{Binding ElementName=Holdergrid, Path=MaxWidth, StringFormat=Max Width: {0}}" Margin="10 0 0 0"></TextBlock>
</StackPanel>
</Grid>
</Window>
當你拖動網格分流到左側,右列將有所無限增長,甚至超過我限制了MaxWidth。如果在第三列定義中將Width="400"
替換爲Width="*"
,則它可以正常工作。顯然,這是實現它的唯一方法。
這可以起作用,但試着將分離器移動超過極限......現在,當您再次嘗試移動分離器時,它一開始就不會先拖動之前的移動距離。這看起來像一個錯誤。 –