【问题标题】:How can I bind to the design instance of the data context如何绑定到数据上下文的设计实例
【发布时间】:2019-02-13 11:01:24
【问题描述】:

我该如何做这样的绑定?

<local:MySubView d:DataContext="{Binding MyParentView.(d:DesignProperties.DataContext)}"/>

我看到 MySubView 没有自动获取 MyParentView 的 DataContext。上面的语法给出的 DataContext 是未知的。

MySubView 用作 MyParentUserControl.Resources 中的 DataTemplate。两个用户控件应具有相同的视图模型。当我像在 MyParentView 中那样创建一个新实例时,它正在工作:

<local:MySubView d:DataContext="{d:DesignInstance local:MyParentView, IsDesignTimeCreatable=True}"/>

但是我怎样才能绑定到同一个实例呢?

【问题讨论】:

  • 您是否尝试过创建StaticResource 并在两个地方都使用它?
  • 谢谢。可以,但无法从 MyParentView 数据上下文访问静态资源。

标签: wpf xaml


【解决方案1】:

这个Post 就是答案。我有同样的情况。绑定在其他地方丢失:

<ContentControl Content="{Binding}" Style="{StaticResource MyContentControlStyle}" >

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-26
    • 2023-03-29
    • 2016-05-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多