I'm doing my first bigger project with WPF and my first project with MVVM.
I want to fill a TreeView with values from a list of a self-defined class.
The part of my XAML looks similar to this:
<Window>
<StackPanel>
...
<TreeView>
<TreeViewItem>
<TreeViewItem />
<TreeViewItem.ItemTemplate>
<HierarchicalDataTemplate
ItemsSource="{Binding ListOfFoo}">
<StackPanel>
<CheckBox VerticalAlignment="Center" Width="50"
Content="{Binding Bar.Description}" IsChecked="{Binding IsChosen}"/>
<TextBox Width="38" VerticalAlignment="Center"
Text="{Binding SomeText}" IsEnabled="{Binding IsChosen}" />
</StackPanel>
</HierarchicalDataTemplate>
</TreeViewItem.ItemTemplate>
</TreeViewItem>
</TreeView>
...
</StackPanel>
</Window>
The property at my ViewModel looks like this:
public List<Foo> ListOfFoo
{
get { return listoffoo; }
set
{
listoffoo = value;
OnPropertyChanged("ListOfFoo");
}
}
Foo has the properties IsChosen, Bar (which is another type with a property Description) and SomeText.
When I execute my code, I can see the TreeView with the first item shown (which has some UI elements that I left out for better reading), but the items (in my test case should be 2) are not shown.
I used the following resources:
(Can someone tell me where the x:Type comes from? I don't have that available in my x Namespace, which is defined as follows:
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
What am I doing wrong? Any help is appreciated.