我有一个ItemsControl,其中的ItemsSource来自我的ViewModel。这可以按预期工作。
我在ItemsControl的DataTemplate中有一个组合框,看起来像这样...
<ComboBox SelectedItem="{Binding Path=RelayType}" ItemsSource="{Binding Path=RelayTypes" />
RelayTypes是ViewModel中的一个属性,但是我不知道如何在ItemsControl中用它来填充ComboBox。
我尝试了以下方法,但是没有运气,我不确定还有什么方法可以尝试...
<ComboBox SelectedItem="{Binding Path=RelayType}" ItemsSource="{Binding Path=DataContext.RelayTypes" />
和
<ComboBox SelectedItem="{Binding Path=RelayType}" ItemsSource="{Binding Path=RelayTypes, Source=DataContext" />
有什么想法吗?
编辑:
这有效:
{Binding Path=DataContext.RelayTypes, RelativeSource={RelativeSource AncestorType=local:MainView}}