wpf - WPF中的Grid Splitter问题

标签 wpf wpf-controls gridsplitter

我想要一个像 VS 2008 一样的布局。其中我想要两列,第二列再次分成两部分。

我在下面提到的 xaml 中做到了这一点,但是 GridSplitter垂直不可见(拆分两列)。
GridSplitter我都想要s 可调整大小。一 GridSplitter调整左手 Pane 和右手 Pane 的大小以及另一个 GridSplitter调整子网格的顶部 Pane 和右 Pane 的大小..

第二个GridSplitter正在处理此 XAML,但我无法生成拆分右侧 Pane 和左侧 Pane 的 XAML 代码。
请帮忙!!

<Window x:Class="AlarmUI_2.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window1" Height="300" Width="300">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <StackPanel Background="Aqua" Grid.Column="0" >
            <TextBlock FontSize="35" Foreground="#58290A" 
                       TextWrapping="Wrap">Left Hand Side</TextBlock>
        </StackPanel>
        <GridSplitter Grid.Column="0" ResizeDirection="Auto" 
                      Grid.RowSpan="1" 
                      HorizontalAlignment="Stretch" 
                      VerticalAlignment="Center"/>
        <Grid Grid.Column="1">
            <Grid.RowDefinitions>            
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <ListBox Grid.Row="0" Background="Red">
                <ListBoxItem>Hello</ListBoxItem>
                <ListBoxItem>World</ListBoxItem>
            </ListBox>
            <GridSplitter Grid.Row="1" Height="5" Background="Gray"
                          VerticalAlignment="Top" HorizontalAlignment="Stretch" />
            <ListBox Grid.Row="1" Background="Violet" Margin="0,5,0,0">
                <ListBoxItem>Hello</ListBoxItem>
                <ListBoxItem>World</ListBoxItem>
            </ListBox>
        </Grid>
    </Grid>
</Window>

最佳答案

将您的垂直分配器更改为

<GridSplitter Grid.Column="0" Width="5" ResizeDirection="Auto" 
            Grid.RowSpan="1" 
            HorizontalAlignment="Right" 
            VerticalAlignment="Stretch"/>

这将是使用 GridSplitter 的更好方法
<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="5"/>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>

    <StackPanel Background="Aqua" Grid.Column="0" >
        <TextBlock FontSize="35" Foreground="#58290A" 
           TextWrapping="Wrap">Left Hand Side</TextBlock>


    </StackPanel>

    <GridSplitter Grid.Column="1" HorizontalAlignment="Stretch"/>

    <Grid Grid.Column="2">
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="5" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <ListBox Grid.Row="0" Background="Red">
            <ListBoxItem>Hello</ListBoxItem>
            <ListBoxItem>World</ListBoxItem>
        </ListBox>
        <GridSplitter Grid.Row="1" Background="Gray" HorizontalAlignment="Stretch"/>
        <ListBox Grid.Row="2" Background="Violet">
            <ListBoxItem>Hello</ListBoxItem>
            <ListBoxItem>World</ListBoxItem>
        </ListBox>
    </Grid>
</Grid>

关于wpf - WPF中的Grid Splitter问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1748168/

相关文章:

c# - 更新MVVM主线程中的进度条

c# - 访问 IEnumerable 的属性

wpf - 使用 Gridsplitter 功能排列项目的项目控件

c# - WPF 网格拆分器 : How to move programmatically?

javascript - 这个嵌套的 jQuery 命令如何正确编写?

wpf - DevExpress 控制 WPF 加载时间

.net - 如何为 Popup 控件编写样式模板?

WPF应用启动问题

c# - xml 命名空间 clr-命名空间中不存在标记 "xxx"。无法发布 WPF Visual C# 项目

c# - XAML 中的映射命名空间不起作用