andyopayne
andyopayne

Reputation: 1368

WPF ListView Stretch Width To Grid Column

I have a grid with two columns each with a width of 1* to be of equal widths. Inside the left-most column, I have a listview but for some reason I can't get the width to automatically stretch to the width of the grid column. I've tried all kinds of things like HorizontalContentAlignment="Stretch" and ScrollViewer.HorizontalScrollBarVisibility="Disabled" both of which were suggested as possible fixes to this issue... but they don't seem to address my issue. Here's my code:

<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

Upvotes: 0

Views: 861

Answers (1)

user1228
user1228

Reputation:

<ListView HorizontalAlignment="Left" 

Well, there's your problem.

Upvotes: 1

Related Questions