为什么我的GridSplitter不出现?

时间:2023-01-16 20:05:27

I have a simple Window that looks like this:

我有一个看起来像这样的简单窗口:

<Window x:Class="*Example.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="3*" />
            <RowDefinition Height="2*" />
        </Grid.RowDefinitions>

        <Label Content="Foo" Margin="5" />
        <Label Grid.Row="1" Content="Bar" Margin="5" />
        <GridSplitter Grid.Row="1" Background="Black" VerticalAlignment="Top" Height="5" />
    </Grid>
</Window>

// The code-behind is empty, except for "InitializeComponent()".

When I run the application, however, no GridSplitter is visible. I also see no GridSplitter during design time.

但是,当我运行应用程序时,没有可见的GridSplitter。我在设计时也看不到GridSplitter。

  • I've made sure that the GridSplitter is in the correct row, and set the VerticalAlignment to Top
  • 我已确保GridSplitter位于正确的行中,并将VerticalAlignment设置为Top

  • I've specified an explicit background color to make sure that the GridSplitter does not blend in.
  • 我已经指定了一个明确的背景颜色,以确保GridSplitter不会混入。

  • I've made sure that the GridSplitter is the last element in the Grid, so I shouldn't be running into ZIndex problems.
  • 我确保GridSplitter是Grid中的最后一个元素,所以我不应该遇到ZIndex问题。

  • Just in case, I've added margins to the Labels to make sure that they are not obscuring the grid (although this should make a difference in this case).
  • 为了以防万一,我已经为标签添加了边距,以确保它们不会模糊网格(尽管这在这种情况下应该有所不同)。

What am I doing wrong?

我究竟做错了什么?

1 个解决方案

#1


6  

You need to set HorizontalAlignment="Stretch":

你需要设置Horizo​​ntalAlignment =“Stretch”:

<GridSplitter Grid.Row="1" Background="Black" VerticalAlignment="Top" HorizontalAlignment="Stretch" Height="5" />

#1


6  

You need to set HorizontalAlignment="Stretch":

你需要设置Horizo​​ntalAlignment =“Stretch”:

<GridSplitter Grid.Row="1" Background="Black" VerticalAlignment="Top" HorizontalAlignment="Stretch" Height="5" />