'WPF binding child controls DataContext to HierarchicalDataTemplate ItemsSource item
I have a collection of Barcodes that contains a collection of Positions. How do I set the DataContext of a custom control to a Position item in the collection?
<TreeView ItemsSource="{Binding SelectedPlate.Barcodes}">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Positions}"
DataType="{x:Type ControlViewModels:BarcodeViewModel}">
<TextBox Text="{Binding Code}"/>
<HierarchicalDataTemplate.ItemTemplate>
<DataTemplate>
<!--The Custom Control that needs to bind to the Position item-->
<ControlViews:PositionControl DataContext="{Binding}"/>
</DataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
