WPF ListView拉伸宽度到网格列

时间:2017-02-10 19:28:44

标签: wpf

我有一个网格,每列有两列,宽度为1*,宽度相等。在最左边的列中,我有一个列表视图,但出于某种原因,我无法将宽度自动拉伸到网格列的宽度。我已尝试过各种类似HorizontalContentAlignment="Stretch"ScrollViewer.HorizontalScrollBarVisibility="Disabled"的内容,这些内容都被建议作为此问题的可能解决方案......但它们似乎无法解决我的问题。这是我的代码:

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="1*"></ColumnDefinition>
        <ColumnDefinition Width="1*"></ColumnDefinition>
    </Grid.ColumnDefinitions>
    <ListView ItemsSource="{Binding Path= Loads}" Grid.Column="0" MinHeight="20" MaxHeight="100" HorizontalAlignment="Left" HorizontalContentAlignment="Stretch" ScrollViewer.HorizontalScrollBarVisibility="Disabled" Margin="6,-3,0,0" SelectedItem="{Binding Path= CurrentLoad}">
        <ListView.ItemTemplate>
            <DataTemplate DataType="local:Loads">
                <StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch">
                    <Button Width="26" Height="26">
                        <StackPanel>
                            <Image Source="{Binding Path=Icon}" Width="24" Height="24" Stretch="Fill"></Image>
                        </StackPanel>
                    </Button>
                    <TextBlock Text="{Binding Path=Name}" FontSize="9" Margin="3,6,3,3"></TextBlock>
                </StackPanel>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
    <StackPanel Margin="0,-2,6,0" Grid.Column="1"></StackPanel>
</Grid

1 个答案:

答案 0 :(得分:1)

<ListView HorizontalAlignment="Left" 

嗯,这是你的问题。