首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何正确设置PropertyPath

如何正确设置PropertyPath
EN

Stack Overflow用户
提问于 2011-06-08 02:46:10
回答 2查看 4.5K关注 0票数 1

如何正确添加PropertyPath?

我需要绑定用户控件DataContext到DataContext,TwoWay。

代码语言:javascript
复制
    var binding = new Binding()
                          {
                              Mode = BindingMode.TwoWay,
                              Source = ((FrameworkElement)sender),
                              Path = new PropertyPath(FrameworkElement.DataContextProperty)
                          };
    binding.Source = ((FrameworkElement) sender);
    changeImage.SetBinding(FrameworkElement.DataContextProperty, binding);
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-06-08 02:50:52

代码语言:javascript
复制
binding.Path = new PropertyPath("DataContext")

另外,如果你能说出你的代码出了什么问题,也会有所帮助。

票数 3
EN

Stack Overflow用户

发布于 2011-06-08 03:07:31

PropertyPath有一个字符串构造器,它接受如下属性路径:

代码语言:javascript
复制
  var binding = new Binding()
                {
                   Mode = BindingMode.TwoWay,
                   Source = ((FrameworkElement)sender),
                   Path = new PropertyPath("DataContext")
                };

或者,Binding有一个构造函数,它将从给定字符串参数创建一个PropertyPath

代码语言:javascript
复制
  var binding = new Binding("DataContext")
                {
                   Mode = BindingMode.TwoWay,
                   Source = ((FrameworkElement)sender)
                };
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6270098

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档