WPF を使用して既存の Winforms プロジェクトの一部を置き換えようとしています。この作品を「ログビューア」と呼びましょう。各ログ エントリは、ヘッダーといくつかの本文で構成されます。ビューアは、これらをスクロール可能な 1 つの長いリストに表示する必要があります。
元の (Winforms) logviewer は、ログ エントリの数とそのサイズが小さい場合は適切に機能しますが、多数の長いエントリを表示する場合に問題が発生します。WPF の virtualizingstackpanel はこれらの問題を解決しますが、WPF、またはそれに関する私の経験不足により、独自の問題がいくつか追加されています。
リストボックスの周りにログビューアウィンドウを構築すると、スクロールが「ピクセルごと」のスムーズなスクロールではなくアイテムごとであるという事実を除いて、完全に機能します。これは.Net 4.5に移行することで修正できると思いますが、それは簡単なオプションではありません。
または、TreeView を中心に構築すると、完全にスクロールしますが、テキストは折り返されません。代わりに、段落ごとに 1 つの長い行を形成します。
ツリービュー バージョンの xaml は次のとおりです。スタイルが非ラッピングの問題を修正するために使用されているように見えるこのSOの質問から大きく借りています。美しくスクロールしますが、それでもラップしません。
<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>
私もこの SO answerに基づいて xaml を試しましたが、それを機能させることはできません - それでもアイテムごとにスクロールします。
どんな助けでも大歓迎です。