Listed below xaml using .Net3.5 -
<ListView Name="RawData" AlternationCount="2" ItemsSource="{Binding}"
ScrollViewer.VerticalScrollBarVisibility="Visible" Grid.Row="1"
Grid.ColumnSpan="4"
IsSynchronizedWithCurrentItem="True"
sorter:GridViewSort.AutoSort="True"
sorter:GridViewSort.ShowSortGlyph="False" >
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Style.Triggers>
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
<Setter Property="Background" Value="LightGray"></Setter>
</Trigger>
</Style.Triggers>
</Style>
</ListView.ItemContainerStyle>
<ListView.View>
<GridView>
<GridViewColumn Header="Date" DisplayMemberBinding="{Binding Path=GetDate}"
Width="Auto" sorter:GridViewSort.PropertyName="GetDateTime"/>
<GridViewColumn Header="Time" DisplayMemberBinding="{Binding Path=GetTime}"
Width="Auto" sorter:GridViewSort.PropertyName="GetDateTime"/>
<GridViewColumn Header="Scan Time" DisplayMemberBinding="{Binding Path=ScanTimeSec}"
sorter:GridViewSort.PropertyName="ScanTimeSecond" Width="Auto"/>
<GridViewColumn Header="Ping Time" DisplayMemberBinding="{Binding Path=PingTimeSec}"
sorter:GridViewSort.PropertyName="PingTimeSec" Width="Auto" />
<GridViewColumn Header="Fault Messages"
DisplayMemberBinding="{Binding Path=ErrorMessages}"
sorter:GridViewSort.PropertyName="ErrorMessages" Width="Auto"/>
</GridView>
</ListView.View>
</ListView>
My problem is with the first and last columns. They do not change automatically to fit the contents of the data. I could use a fixed width, but this will cause problems later in the project when I allow users to change the font size.
Each solution I found is like setting width = "auto", and WPF will do it for you. However, he does not. Since I'm a little new to WPF, I'm not sure what to do.
source
share