WPF - Listview Databound Column Width Problem
Given 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"
Displa开发者_如何转开发yMemberBinding="{Binding Path=ErrorMessages}"
sorter:GridViewSort.PropertyName="ErrorMessages" Width="Auto"/>
</GridView>
</ListView.View>
</ListView>
My problem is with the first and last columns. They are not automatically resizing to fit the contents of the data. I could use a fixed width, but that will cause problems later in the project when I let users adjust font size.
Every solution I've found seems to be to set the width="auto" and WPF will do this for you. However, it doesn't do it. So as a bit of a newbie at WPF, I'm not sure what to do.
please remove the auto property for Width.You can manually set the width.Like Width="100". I fetched just like this problem and solve by manually enter the width.
精彩评论