wpf - 如何在 Windows 8 商店应用程序中访问 Parent 的 DataContext

标签 wpf xaml windows-8 windows-runtime winrt-xaml

这是基于 XAML 的应用程序 (WPF/Silverlight/WinRT) 中的常见情况。

WPF 相关链接 -> WPF Databinding: How do I access the "parent" data context?
RelativeSourceAncestorType , 和 Mode=FindAncestor通常会在 WPF 中进行救援。

WinRT API 中缺少这两者。如何访问 parent 的(可能不是直接的),DataContext ?

(我知道 TemplateBindingElementBinding 但两者都不适合在 DataTemplate 中使用)。

最佳答案

我只是有同样的问题。大概这很常见??

这是一个有效的粗略解决方案:

  • 将顶级元素的 Tag 属性绑定(bind)到 DataContext
    <Grid Name="gridTop" Tag="{Binding}" />
    
  • 在嵌套元素中通过 ElementName 绑定(bind)你想要的属性,即
    {Binding Tag.SomeProp, ElementName=gridTop}
    
  • 关于wpf - 如何在 Windows 8 商店应用程序中访问 Parent 的 DataContext,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15366609/

    相关文章:

    wpf - MVVM : Decouple Model from ViewModel

    c# - Windows 8 应用程序中的 GridView SelectionMode 最多有 2 个选择

    c# - ItemsControl 与其项目源不一致 - WPF 列表框

    c# - MVVM 共享属性

    .net - 样式化 XAML slider 控件 - 如何停止在 PointerOver 上更改拇指背景?

    wpf - 如何清除 MVVM 中的文本框?

    c# - WPF 的打印对话框和打印预览对话框

    windows-8 - Windows 8 开发者预览版的 SDK 在哪里

    c# - BorderStyle.Fixed3D 在 Windows 8 上呈现平面

    c# - 带有参数的 Dispatch.Invoke( new Action...)