TreeViewへのデータバインディングで躓いております。
お世話になっております。
WPFウィンドウのTreeView
へのデータバインディングについて、
テストとしてインスタンス化時に、データを渡している筈ですが、
全く反映されず、バグ原因も掴めず困っています。
WEBにのっかってるソースそのまま書いたりしても表示されないので、
設定のような部分で間違えているのかもしれませんが・・・
(ソースはC#しかなかったので、.NETの文法に書き換えをしています)
TreeView
コントロールへのDataContext
へはきちんと渡したいオブジェクトを渡しているので、近いところにあると思ってはいます。
なぜ表示されないのか、ご助言頂きたいです。
<Window x:Class="MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:WpfApplication1" mc:Ignorable="d" Title="MainWindow" Height="350" Width="525"> <Grid> <TreeView x:Name="TreeView" ItemsSource="{Binding PluginEntries}"> <TreeView.ItemTemplate> <HierarchicalDataTemplate ItemsSource="{Binding Path=Functions}"> <HierarchicalDataTemplate.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Path=Name}"/> </DataTemplate> </HierarchicalDataTemplate.ItemTemplate> <TextBlock Text="{Binding Path=Name}"/> </HierarchicalDataTemplate> </TreeView.ItemTemplate> </TreeView> </Grid> </Window>
vb
1'Model & ViewModel 2Public Class ViewModel 3 Private _PluginEntries As List(Of Plugin) 4 Public Property PluginEntries As List(Of Plugin) 5 Get 6 Return _PluginEntries 7 End Get 8 Set(value As List(Of Plugin)) 9 _PluginEntries = value 10 End Set 11 End Property 12 13 Sub New() 14 Me.PluginEntries = New List(Of Plugin) 15 Me.PluginEntries.Add(New Plugin With { 16 .Name = "あああ", 17 .Functions = New List(Of Plugin) From { 18 New Plugin With {.Name = "いいい", .Functions = New List(Of Plugin) From { 19 New Plugin With {.Name = "ううう", .Functions = New List(Of Plugin) From { 20 New Plugin With {.Name = "えええ"} 21 }} 22 }} 23 } 24 }) 25 End Sub 26End Class 27 28 29Public Class Plugin 30 Public Name As String 31 Public Functions As List(Of Plugin) 32End Class
回答1件
あなたの回答
tips
プレビュー