C# 使用ItemSource绑定访问ListView中的另一个datacontext
我正在使用XAML进行一个MVVM项目。 在具有ItemSource绑定的ListView中操作时,访问外部元素的属性时遇到问题 XAML: 视图模型:C# 使用ItemSource绑定访问ListView中的另一个datacontext,c#,xaml,listview,mvvm,uwp,C#,Xaml,Listview,Mvvm,Uwp,我正在使用XAML进行一个MVVM项目。 在具有ItemSource绑定的ListView中操作时,访问外部元素的属性时遇到问题 XAML: 视图模型: private ObservableCollection<ChosenField> _bibTexFields; public ObservableCollection<ChosenField> BibTexFields { get { return _bibTexFields;
private ObservableCollection<ChosenField> _bibTexFields;
public ObservableCollection<ChosenField> BibTexFields
{
get { return _bibTexFields; }
set
{
_bibTexFields = value;
OnPropertyChanged();
}
}
private observeCollection\u bibTexFields;
公共可观测收集BibTexFields
{
获取{return\u bibTexFields;}
设置
{
_bibTexFields=值;
OnPropertyChanged();
}
}
我要做的是从列表视图
中访问视图模型
,这样我就可以生成一个绑定到updateFiledFieldsCommand
属性的命令
我曾尝试研究
相对资源
绑定,但似乎无法实现。尝试将其绑定到数据上下文也不起作用。您还可以使用ElementName:
<CheckBox HorizontalAlignment="Right" IsChecked="{Binding IsChecked, Mode=TwoWay}" Command="{Binding DataContext.UpdateFilledFieldsCommand, ElementName=BibTexFields}"/>
然而,相对资源也应该起作用。通过快速搜索,我发现:虽然我不知道UWP应用程序中是否存在所有功能,但看起来很好。谢谢,这就成功了!
private ObservableCollection<ChosenField> _bibTexFields;
public ObservableCollection<ChosenField> BibTexFields
{
get { return _bibTexFields; }
set
{
_bibTexFields = value;
OnPropertyChanged();
}
}
<CheckBox HorizontalAlignment="Right" IsChecked="{Binding IsChecked, Mode=TwoWay}" Command="{Binding DataContext.UpdateFilledFieldsCommand, ElementName=BibTexFields}"/>