附属物:检查装订 [英] Attached property: Check binding

查看:146
本文介绍了附属物:检查装订的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在运行时,是否有一种快速了解特定附加属性绑定的方法?

Is there a quick way of knowing what a particular attached property is bound to, at runtime?

我正在调试一个UserControl(继承 ItemsControl )将其项目的 Canvas.Left Canvas.Top 绑定到ViewModel对象的两个属性,通过风格。在运行时,我在某个位置放置一个断点,并且要检查 Canvas.Left 附加属性的绑定。

I'm debugging a UserControl (that inherits ItemsControl) which binds Canvas.Left and Canvas.Top of its items to two properties of the ViewModel objects, through a style. At runtime, I place a breakpoint at a certain location and want to inspect the binding of Canvas.Left attached property.

请注意,我不想看到项目附加属性的当前值。我可以通过检查QuickWatch或即时窗口中 Canvas.GetLeft(myItem)的值来轻松实现。我想检查这里的实际绑定,即该附加属性绑定的VM属性名称 myItem

Note that I do not want to see the current value of the attached property for an item. I can easily do that by inspecting the value of Canvas.GetLeft(myItem) in the QuickWatch or Immediate windows. I want to check the actual binding here, i.e. the VM property name to which this attached property is bound for myItem.

我已经尝试过Snoop,不幸的是没有显示附加属性的绑定(如果我没有错过任何明显的东西)。

I have tried Snoop already, which unfortunately doesn't show bindings of attached properties (if I didn't miss something obvious).

推荐答案

您可以通过编辑方式获取附加属性,方法与获取正常的依赖属性绑定相同。即从代码中获取 Canvas.LeftProperty 附加属性绑定的控件与名称 myItemsControl

You can get the attached property binding programmatically the same way as you get normal dependency property binding. I.e. from code behind to get the Canvas.LeftProperty attached property binding of the control with the name myItemsControl:

BindingExpression bindingExpression = myItemsControl.GetBindingExpression(Canvas.LeftProperty);
Binding parentBinding = bindingExpression.ParentBinding;

这篇关于附属物:检查装订的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆