プロパティ内にListViewを持つUserControlがItemTemplateあり、ComboBoxがあります。このComboBoxに2つのデータコンテキストを使用する必要があります
- UserControlのItemsSourceDataContext
- ListViewItemからのSelectedItemDataContext
プロパティ内にListViewを持つUserControlがItemTemplateあり、ComboBoxがあります。このComboBoxに2つのデータコンテキストを使用する必要があります
バインディングで使用RelativeSourceして、ビジュアルツリーをトラバースしてを見つけることができますDataContext for UserControl。
一方、の場合、RelativeSource自体ListViewItemは必要ありません。Combobox will inherit the DataContext of its parent which is ListViewItemあなたの構造はこのように見えるでしょう-
<UserControl>
<ListView>
<ListView.ItemTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding DataContext.CollectionSource,
RelativeSource={RelativeSource FindAncestor,
AncestorType=UserControl}}"
SelectedItem="{Binding YourItemHere}"/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</UserControl>