带分离器的伸展面板
问题描述:
我想实现一个带有三个面板和两个分离器(水平和垂直分离器)的基本WPF布局。带分离器的伸展面板
左侧和底部的两个面板必须可以放大并且一个面板必须相应地拉伸。
下面是一个简单的XAML:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="5"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackPanel Background="Aqua" Grid.Column="0" Name="leftPanel" >
<TextBlock FontSize="35" Foreground="#58290A" TextWrapping="Wrap">Left Hand Side</TextBlock>
</StackPanel>
<GridSplitter Grid.Column="1" HorizontalAlignment="Stretch"/>
<Grid Grid.Column="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="5" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Label Content="... Clien Area .. Has to Stretch vertically and horizontally" Margin="10"></Label>
<Button Click="LeftButton_Click" Margin="10">Close Left Panel</Button>
<Button Click="BottomButton_Click" Margin="10">Close Bottom Panel</Button>
</StackPanel>
<GridSplitter Grid.Row="1" Background="Gray" HorizontalAlignment="Stretch"/>
<ListBox Grid.Row="2" Background="Violet" Name="bottomPanel">
<ListBoxItem>Hello</ListBoxItem>
<ListBoxItem>World</ListBoxItem>
</ListBox>
</Grid>
</Grid>
和代码隐藏:?
private void LeftButton_Click(object sender, RoutedEventArgs e)
{
leftPanel.Visibility = (leftPanel.Visibility == System.Windows.Visibility.Visible)? System.Windows.Visibility.Collapsed : System.Windows.Visibility.Visible;
}
private void BottomButton_Click(object sender, RoutedEventArgs e)
{
bottomPanel.Visibility = (bottomPanel.Visibility == System.Windows.Visibility.Visible) ? System.Windows.Visibility.Collapsed : System.Windows.Visibility.Visible;
}
预期:(任何WPF专家围绕提出一个解决方案,其客户端此代码不能正常工作面积(拉伸)和分配器在同一时间?
DockPanel将完美的工作,但我需要分离器!
谢谢。
感谢您的快速和正确的答案。它可以工作,但有一个错误。如果我触摸(调整分隔线),它会立即停止工作。我认为原因是宽度属性正在从自动更改为某种尺寸,所以,任何优雅的解决方案将宽度换回到自动? – user1153896 2012-03-28 17:29:54
当我做这样的事情时,我也隐藏了GridSplitter及其列,当一边崩溃时没有任何意义。 – 2012-03-28 17:36:41