I have a list view that shows some logs (of type LogItem). The ListView.View is set to a GridView in XAML. The GridView has two columns where the data templates for each column is set to a textbox. The first column binds to a DateTime property of the LogItem, so the width of the first column could be set to Auto (preferred) or even a fixed width i required.
The second gridviewcolumn is binding to a log message string, so it could have any width.
My question is, how can I make sure all text is visible in the listview such that I get a scrollbar in the listview if the log message width is larger than the listview's width, and that all the text is visible?
At the moment the size of the second column seems to be set by the first item added to the collection that the ListView binds to, then the width never updates. So typically I just see a small part of the log messages and the second column header does not even span the complet ListView width.
I have looked around for a solution to the problem. There seems to be more people asking the same question, but so far none of the answers I have found has solved the problem. I hope someone could help to guide me in the right direction, what have I missed.
XAML code below
<ListView Grid.Row="1"
HorizontalAlignment="Stretch"
IsSynchronizedWithCurrentItem="False"
ItemsSource="{Binding LogItems}"
x:Name="LogListView"
FontSize="14">
<!--:GridViewColumnResize.Enabled="True" -->
<ListView.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Gray" Offset="1"/>
<GradientStop Color="White"/>
</LinearGradientBrush>
</ListView.Background>
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="Background" Value="{Binding BackColor}"/>
<Setter Property="TextElement.Foreground" Value="White"/>
<Style.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="true" />
</MultiTrigger.Conditions>
<Setter Property="Background" Value="Gold" />
<Setter Property="BorderBrush" Value="Black" />
<Setter Property="TextElement.Foreground" Value="Black"/>
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="true" />
</MultiTrigger.Conditions>
<Setter Property="Background" Value="Gold" />
<Setter Property="BorderBrush" Value="Black" />
<Setter Property="TextElement.Foreground" Value="Black"/>
</MultiTrigger>
</Style.Triggers>
</Style>
</ListView.ItemContainerStyle>
<ListView.View>
<GridView>
<GridViewColumn Header="{Binding TimeText}" Width="Auto">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock x:Name="TimeLabel" Text="{Binding CreationTime, StringFormat='{}{0:hh:mm:ss.fff}'}" Grid.Column="0"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="{Binding MessageText}">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Message}" Grid.Column="1"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
Edit: The full xaml code pastebin.com/24HgAcML