xaml - ElementName 绑定(bind)不解析属性

标签 xaml windows-runtime resharper winrt-xaml win-universal-app

当我将某些内容绑定(bind)到 SelectedItem 时使用 ElementName 的 ListView ,无法解析属性。

我仍然可以构建并运行我的应用程序,但由于这个错误,我不确定我没有犯任何拼写错误。

我阅读并尝试了 ElementName Binding is failing 中给出的答案但是Source={x:Reference ...} WinRT框架中似乎不存在。

举个例子:

我的页面有一个属性MyContainerObjectIEnumerable<MyParentObject>里面叫MyParents 。每个MyParentObject有一个 IEnumerable<MyChildObject>MyChildren里面。

我的页面的 DataContext:

DataContext="{Binding RelativeSource={RelativeSource Self}}"

我的 ListView 具有以下 XAML 属性:

  • x:Name = "FirstListView"
  • ItemsSource = {Binding MyContainerObject.MyParents}

然后我有另一个具有以下 XAML 属性的 ListView:

  • x:Name = "SecondListView"
  • ItemsSource = "{Binding SelectedItem.MyChildren, ElementName=FirstListView}"

现在 ReSharper 向我发出以下警告:

Cannot resolve property 'MyChildren' in data context of type 'object'.

最佳答案

将其添加到您的 ListView 中:

d:DataContext="{d:DesignInstance model:MyParentObject}"

关于xaml - ElementName 绑定(bind)不解析属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24884610/

相关文章:

C# - 什么是特定于文化的?

c# - 立即更改 namespace

c# - 使用自定义项目模板在 ComboBox 中显示所选项目

c# - WPF/UWP : What is the difference between DependencyObject's GetValue() and ReadLocalValue()?

c# - WPF:ListView 中列表属性的总和

deployment - Windows 8 模拟器命令行界面

windows-runtime - Winrt GridView 虚拟化

c# - 解决构造函数中的虚拟成员调用

c# - 绑定(bind)到不在代码隐藏中的 RoutedUICommand

c# - 在 uwp 中使用 VisualStateManager 更改按钮前景