これはロギング プロジェクトです。タイトルはアイテムの名前を提供し、メッセージは各段階をログに記録します。そのため、タイトルごとに多くのメッセージがあります。
質問をする目的で、オブジェクトを単純化しています。
私の Log クラスには 2 つのプロパティがあります。
List<LogDetails>
string Title
そして、私の LogDetails クラスには 1 つのプロパティがあります。
string Message
メッセージを XAML にバインドできません。タイトルは必要に応じてバインドします。
私のxamlコード:
<Window x:Class="BackUps.Logging.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:myData="clr-namespace:BackUps.Logging"
Title="MainWindow"
Height="350"
Width="525">
<Grid>
<TreeView ItemsSource="{Binding}">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate DataType="{x:Type myData:Log}"
ItemsSource="{Binding LogDetailsList}">
<TextBlock Text="{Binding Title}" />
<HierarchicalDataTemplate.ItemTemplate>
<DataTemplate DataType="{x:Type myData:LogDetails}">
<StackPanel>
<TextBlock Text="{Binding Message}" />
</StackPanel>
</DataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
</Grid>
そして私のコードビハインド
public MainWindow(List<Log> logs)
{
InitializeComponent();
this.DataContext = logs;
}
私の結果は次のとおりです(欠落しているエントリを確認できる場所):
これは Auto のウィンドウで、バインドしようとしているオブジェクトが表示されています。
私は何を見逃したか、間違っていますか?