-2

I have an WPF ListView with three columns. I see that in my ListView appears an extra empty space(column) on the right handside and I do not know why. How can I remove this extra space using XAML?

enter image description here

<ListView x:Name="MyListView"
          Grid.Column="0"                             
          AlternationCount="{Binding pathList.Count}"
          ItemsSource="{Binding pathList}" 
          IsSynchronizedWithCurrentItem="True">
    <ListView.ItemContainerStyle>
        <Style TargetType="ListViewItem">
            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        </Style>
    </ListView.ItemContainerStyle>
    <ListView.View>
        <GridView>
            <GridViewColumn x:Name="LvItemId" 
                            Header="#"
                            Width="20"
                            DisplayMemberBinding="{Binding (ItemsControl.AlternationIndex),
                            RelativeSource={RelativeSource AncestorType=ListViewItem}}"/>
            <GridViewColumn Header="Path"
                            Width="350"
                            CellTemplate="{StaticResource NameColumnTemplate}"/>
            <GridViewColumn  Header="Edit | Delete"
                             Width="80"
                             CellTemplate="{StaticResource AddDelItemTemplate}"/>
        </GridView>
    </ListView.View>
</ListView>
Willy
  • 9,848
  • 22
  • 141
  • 284
  • see https://stackoverflow.com/questions/911243/wpf-extend-last-column-of-listviews-gridview – ZSH Mar 15 '22 at 10:20
  • @ZSH these solutions are not working for me. i have tried several of them discussed there. – Willy Mar 16 '22 at 11:35

1 Answers1

1

Set the HorizontalAlignment property of the ListView to Leftto prevent it from stretching horizontally:

<ListView x:Name="MyListView"
          Grid.Column="0"                             
          AlternationCount="{Binding pathList.Count}"
          ItemsSource="{Binding pathList}" 
          IsSynchronizedWithCurrentItem="True"
          HorizontalAlignment="Left">
          ...
mm8
  • 163,881
  • 10
  • 57
  • 88