0

Please help me determine how I can adjust this code make the Grid in the ListView.ItemTemplate stretch to fit horizontally. It presently is overflowing on the x-axis.

<ListView ItemsSource="{Binding Results}" Background="Blue" Margin="2" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" >
    <ListView.ItemsPanel>
        <ItemsPanelTemplate>
            <StackPanel Margin="3" Background="Pink" HorizontalAlignment="Stretch"  ></StackPanel>
        </ItemsPanelTemplate>
    </ListView.ItemsPanel>
    <ListView.ItemTemplate>
        <DataTemplate>
            <Grid Background="yellow" Margin="0,5" HorizontalAlignment="Stretch" >
                      <OtherContentHere  Removed />
            </Grid>
        <DataTemplate>
    </ListView.ItemTemplate>
</ListView>

I am open to any suggestions. Am I doing this correctly? or should I bind the Grid.Width to the Column? or something else?

Glenn Ferrie
  • 10,290
  • 3
  • 42
  • 73
  • Since you already have `HorizontalContentAlignment="Stretch"` your code does already work. Also make sure that the parent element of the ListView is suitable. Besides that, consider using the simpler ListBox instead of ListView, which you usually only use when you set its View property. – Clemens Jul 19 '21 at 20:20
  • my code still renders with a horizontal scrollbar on the ListView. does this inherently work differently with ListView vs. ListBox? the post that was referred to closed this post references listbox, perhaps I should switch to that type – Glenn Ferrie Jul 20 '21 at 02:54
  • ListBox wouldn't make difference. The problem is perhaps the `OtherContentHere` that enforces a minimum width. – Clemens Jul 20 '21 at 07:48

0 Answers0