【问题标题】:Can a converter being used in a Source of a Binding可以在绑定源中使用转换器吗
【发布时间】:2013-12-19 10:02:38
【问题描述】:
Text="{Binding MyTextProperty, RelativeSource={RelativeSource FindAncestor, 
                                            AncestorType=local:MyUserControl}}"

在上面的代码中,我可以将MyUserControl 作为我的源,但MyTextProperty 位于MyUserControl 内的另一个控件中。所以我可以使用转换器并获取“MyUserControl”并将相应的控件作为 Source 返回。

这可能吗?

【问题讨论】:

    标签: wpf xaml data-binding binding


    【解决方案1】:

    您可以将内部控件公开为 MyUserControl 中的公共属性:

    public class MyUserControl
    {
        public MyInnerControl InnerControl { get; set; }
    }
    

    并在绑定的属性路径中使用它,如下所示:

    Text="{Binding InnerControl.MyTextProperty,
        RelativeSource={RelativeSource FindAncestor, AncestorType=local:MyUserControl}}"
    

    【讨论】:

      猜你喜欢
      • 2011-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-13
      相关资源
      最近更新 更多