控件出现在GridSplitter下面

时间:2014-07-02 12:42:22

标签: c# .net wpf

我的应用程序中有一个GridSplitter,ListView控件总是出现在Splitter下面。如何在不强制ListView的固定宽度的情况下使ListView控件适合左侧GridSplitter的范围内?

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="300" />
        <ColumnDefinition Width="2*" />
    </Grid.ColumnDefinitions>

    <Grid Margin="0, 25, 0, 22">
        <ScrollViewer ScrollViewer.CanContentScroll="True" VerticalScrollBarVisibility="Auto">
            <ListView x:Name="list" ItemsSource="{Binding Messages}" Grid.Column="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                <DataTemplate>
                    <ListViewItem>
                        <TextBlock Text="sd" />
                    </ListViewItem>
                </DataTemplate>
            </ListView>
        </ScrollViewer>
    </Grid>

    <GridSplitter Width="5" HorizontalAlignment="Right" VerticalAlignment="Stretch" Background="#FFCFE5F0" Margin="0, 25, 0, 22" />
</Grid>

2 个答案:

答案 0 :(得分:1)

将它们放在

列中
<Grid Margin="0, 25, 0, 22" Grid.Column = 0 
<GridSplitter Grid.Column = 1 

答案 1 :(得分:1)

GridSplitter添加到相应的列中。试试这个:

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="300" />
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition Width="2*" />
    </Grid.ColumnDefinitions>
    <Grid>
        <ScrollViewer ScrollViewer.CanContentScroll="True" VerticalScrollBarVisibility="Auto">
            <ListView x:Name="list" ItemsSource="{Binding Items}" Grid.Column="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                <DataTemplate>
                    <ListViewItem>
                        <TextBlock Text="sd" />
                    </ListViewItem>
                </DataTemplate>
            </ListView>
        </ScrollViewer>
    </Grid>
    <GridSplitter Grid.Column="1" Width="5" HorizontalAlignment="Right" VerticalAlignment="Stretch" Background="#FFCFE5F0" Margin="0, 25, 0, 22" />
</Grid>