我GridSplitter在我的WPF应用程序中使用了一个,并希望从代码中将其设置为特定的初始位置.我一直坚持GridSplitter将特定值设置为Height关联属性时的行为RowDefinition.
这是我举例说明这个问题.我已添加TextBlocks以显示RowDefinition.Height属性的实际值.
<Grid>
<Grid.RowDefinitions>
<RowDefinition x:Name="RowDef1" Height="*" MinHeight="20"/>
<RowDefinition Height="Auto" />
<RowDefinition x:Name="RowDef2" Height="*" MinHeight="20"/>
</Grid.RowDefinitions>
<DockPanel Grid.Row="0" LastChildFill="True" >
<TextBlock FontSize="16" VerticalAlignment="Top" Text="Upside Height: "/>
<TextBlock x:Name="Tbl1" FontSize="16" Text="{Binding Height}"/>
</DockPanel>
<GridSplitter Grid.Row="1" Height="10" HorizontalAlignment="Stretch" ResizeBehavior="PreviousAndNext" Background="Black" />
<DockPanel Grid.Row="2" LastChildFill="True" >
<TextBlock FontSize="16" VerticalAlignment="Top" Text="Downside Height: "/>
<TextBlock x:Name="Tbl2" FontSize="16" Text="{Binding Height}"/>
</DockPanel>
</Grid>
Run Code Online (Sandbox Code Playgroud)
namespace WpfGridSplitterTest
{
public partial class MainWindow : Window
{ …Run Code Online (Sandbox Code Playgroud)