1
我正在嘗試使用項目列表(ParentCredentials)填充組合框,它是項目控件的一部分。問題是這些ParentCredentials與itemscontrol綁定的項目處於同一級別。不知道這是明確的,但如果你看看視圖模型應該更有意義在項目控件中綁定組合框
這是我的視圖模型:
public class AccessControlViewModel : INotifyPropertyChanged
{
public ObservableCollection<LogonCredential> Credentials
{...}
public List<string> ParentCredentials
{...}
}
,我有以下XAML。
<ItemsControl ItemsSource="{Binding AccessControl.Credentials}" HorizontalContentAlignment="Stretch">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid >
<Grid.ColumnDefinitions >
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Content="{Binding Path=DisplayName}"/>
<ComboBox Grid.Column="2" ItemsSource="{Binding Source={RelativeSource AncestorType={x:Type vm:ResourceViewModel}}, Path=AccessControl.ParentCredentials}">
</ComboBox>
...
我該如何做這個綁定?另請注意,AccessControl是ResourceViewModel類的一部分。