I am new to WPF, and trying to develop a small application using DataBinding following the MVVM paradigm.
I am trying to provide a binding functionality to the ObservableCollection of Documents (my type). The First Label would display a Documents path (available through Attribute property), while the next children - Pages of the Documents - would display appropriate information: page index and page content (an image).
Here is an issue - how can I create a lookup binding to a parent Label? On Button Click command I would like to pass the documents path, which was available earlier in the first DataTemplate.
Is there a way to tackle this issue?
How would you recommend going around it?
Also, is there a better way to tackle "nested" structures (collections within collections)?
Thanks in advance.
Expand|Select|Wrap|Line Numbers
- <ItemsControl ItemsSource="{Binding Documents}">
- <ItemsControl.ItemTemplate>
- <DataTemplate>
- <StackPanel>
- <Label Content="{Binding Path=Attribute.Path}"/>
- <ItemsControl ItemsSource="{Binding Pages}">
- <ItemsControl.ItemTemplate>
- <DataTemplate>
- <StackPanel>
- <Label Content="{Binding Index}"/>
- <Button Content="{Binding Content}"
- Command="{x:Static viewModel:DocViewModel.Tests }"
- CommandParameter="{Binding Path=Attribute.Path}"/>
- </StackPanel>
- </DataTemplate>
- </ItemsControl.ItemTemplate>
- </ItemsControl>
- </StackPanel>
- </DataTemplate>
- </ItemsControl.ItemTemplate>
- </ItemsControl>