English 中文(简体)
• 如何在《框架》中添加识别依赖性财产的内容?
原标题:How to add callbacks to Framework Element s Visibility Dependency Property?
  • 时间:2011-10-11 14:15:12
  •  标签:
  • c#
  • .net
  • wpf

I m 采用一种依赖性财产处理框架要素的缺失。

财产能够处理 f/脱硫的消亡,只要 an化元素的可见性财产发生变化,就可登记回落方法。

此前的编码员就是这样做的:

UIElement.VisibilityProperty.AddOwner(typeof (FrameworkElement), new FrameworkPropertyMetadata(Visibility.Visible, VisibilityChanged,                                                                           CoerceVisibility));

这里的问题是,《框架要素》已经是显露性财产的所有者,因此触发了一种通过表达方式(简直)达到的例外。

为了解决这一问题,我注意到,属地财产有“OverwriteMetadata”方法,允许某人在我的“框架要素”中超出特定类型的元数据。

因此,我可以采用以下办法:

UIElement.VisibilityProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(Visibility.Visible, VisibilityChanged, CoerceVisibility));

我的问题是:

如何安全地超越《框架》的可见性元数据? 如果不安全,我还有其他什么选择?

EDIT: Well, scratch that... 很明显,超额填写元数据会引发另一个例外:“通用元数据已经登记用于“框架要素”。

如果我不能够增加所有人或超出元数据,我怎么能够补充扶养财产的追索方法?

我不得不制造一个来自框架要素的类别,把它作为显露性财产的所有者,并对使用该财产的控制与衍生类别相同?

最佳回答

如果没有其他hoo子,你可使用DependencyPropertyDescriptor,添加经过改动的操作人员:

var desc = DependencyPropertyDescriptor.FromProperty(FrameworkElement.VisibilityProperty, typeof(FrameworkElement));
desc.AddValueChanged(this.OnVisibilityChanged);

但是,FrameworkElement 下定义了< IssibleChanged 活动——请您使用吗?

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签