0

我有一个列表视图,当我手动调整列宽时,整个列表视图变得更大,到目前为止一切都很好。但是当我缩小列时,列表视图仍然保持宽度。列表视图是否也可能随着列宽而缩小?

下面是一个简单的例子:

<Grid>
        <Grid.Resources>
            <XmlDataProvider x:Key="Data">
                <x:XData>
                    <Data xmlns="">
                        <Item ID="1"/>
                        <Item ID="2"/>
                        <Item ID="3"/>
                    </Data>
                </x:XData>
            </XmlDataProvider>
        </Grid.Resources>

        <ScrollViewer>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>

            <ListView DataContext="{Binding Source={StaticResource Data}, XPath=/Data}"
                      ItemsSource="{Binding XPath=Item}" SelectionMode="Single">                  
                <ListView.View>
                    <GridView>
                        <GridViewColumn Header="ID" DisplayMemberBinding="{Binding XPath=@ID}"/>
                    </GridView>
                </ListView.View>
            </ListView>

            <TextBlock Text="Test" Grid.Column="1"/>
            </Grid>
        </ScrollViewer>
    </Grid>
4

1 回答 1

0

我找到了一个解决方案,它可能不是最好的,但它对我有用。我在列之间添加了一个gridsplitter,并将列宽设置为*。

<Grid>
        <Grid.Resources>
            <XmlDataProvider x:Key="Data">
                <x:XData>
                    <Data xmlns="">
                        <Item ID="1"/>
                        <Item ID="2"/>
                        <Item ID="3"/>
                    </Data>
                </x:XData>
            </XmlDataProvider>
        </Grid.Resources>

        <ScrollViewer>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="3"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>

            <ListView DataContext="{Binding Source={StaticResource Data}, XPath=/Data}"
                      ItemsSource="{Binding XPath=Item}" SelectionMode="Single">                  
                <ListView.View>
                    <GridView>
                        <GridViewColumn Header="ID" DisplayMemberBinding="{Binding XPath=@ID}"/>
                    </GridView>
                </ListView.View>
            </ListView>

            <GridSplitter Grid.Column="1" Width="3" VerticalAlignment="Stretch" HorizontalAlignment="Center" Background="Transparent" ResizeBehavior="PreviousAndNext"/>


            <TextBlock Text="Test" Grid.Column="2"/>
        </Grid>
        </ScrollViewer>
    </Grid>
于 2012-09-11T07:22:49.117 回答