I am attempting to replace a piece of an existing Winforms project using WPF. Let's call this piece a 'log viewer'. Each log entry consists of a header and some body text. The viewer should display these in one long scrollable list.
The original (Winforms) logviewer works well when the number of log entries, and their size, is small, but it suffers from some problems when displaying large numbers of long entries; the WPF virtualizingstackpanel solves these problems, but WPF, or my lack of experience with it, is adding some problems of its own.
If I build the logviewer window around a ListBox, it works perfectly except for the fact that scrolling is by item rather than smooth scrolling 'by pixel'. I gather this can be fixed by moving to .Net 4.5 but that's not a simple option.
Alternatively if I build it around a TreeView, it scrolls perfectly but the text does not wrap; instead it forms one long line per paragraph.
Here's the xaml for the treeview version; it borrows heavily from this SO question where the style seems to be used to correct the non-wrapping issue. It scrolls beautifully, but it still doesn't wrap.
<Window x:Class="zCasesheet.wCasesheet"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:gl="clr-namespace:System.Globalization;assembly=mscorlib"
Title="MainWindow" Height="440" Width="674">
<Window.Resources>
<Style x:Key="MyTreeViewItemStyle" TargetType="{x:Type TreeViewItem}">
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="SnapsToDevicePixels" Value="true"/>
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="VerticalContentAlignment" Value="Stretch"/>
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TreeViewItem}">
<Border Name="myBorder"
SnapsToDevicePixels="true"
CornerRadius="0,0,0,0"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
BorderThickness="0"
BorderBrush="Transparent"
Height="Auto"
Margin="1,1,1,3"
Background="Transparent">
<ContentPresenter Grid.Column="1" x:Name="PART_Header" HorizontalAlignment="Stretch" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" ContentSource="Header"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid Name="grCasesheet" Background="#FFF6E7C9">
<Grid.RowDefinitions>
<RowDefinition Height="356*" />
<RowDefinition Height="45" />
</Grid.RowDefinitions>
<TreeView HorizontalAlignment="Stretch" Margin="2,2,2,0" VerticalAlignment="Top" Name="lstNarratives" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.CanContentScroll="True" >
<TreeView.ItemTemplate >
<DataTemplate >
<Grid >
<Grid.RowDefinitions>
<RowDefinition Height="35" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBox Grid.Row="0" Background="Honeydew" HorizontalAlignment="Stretch" BorderBrush="Black" Text="{Binding Path=HeaderText, StringFormat=d, ConverterCulture={x:Static gl:CultureInfo.CurrentCulture} }"/>
<TextBlock Grid.Row="1" TextWrapping="Wrap" HorizontalAlignment="Stretch" Text="{Binding Path=BodyText}" Margin="10,10,10,10"/>
</Grid>
</DataTemplate >
</TreeView.ItemTemplate >
</TreeView>
</Grid>
I've also tried xaml based on this SO answer, but I can't get that to work either - it still scrolls by item.
Any help much appreciated.