4

I have a simple Window that looks like this:

<Window x:Class="StackOverflowExample.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.

  • I've made sure that the GridSplitter is in the correct row, and set the VerticalAlignment to Top
  • I've specified an explicit background color to make sure that the GridSplitter does not blend in.
  • I've made sure that the GridSplitter is the last element in the Grid, so I shouldn't be running into ZIndex problems.
  • 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?

4

1 回答 1

6

您需要设置HorizontalAlignment="Stretch"

<GridSplitter Grid.Row="1" Background="Black" VerticalAlignment="Top" HorizontalAlignment="Stretch" Height="5" />
于 2011-08-01T20:09:54.723 回答