How can I add logic to an existing dependency-property callback?

▼魔方 西西 提交于 2019-11-28 11:04:10

WPF will merge the property metadata for you when you call OverrideMetadata, no need to pass it the original Metadata object. So all you have to do is

UIElement.RenderTransformOriginProperty.OverrideMetadata(typeof(foo), new PropertyMetadata(new PropertyChangedCallback(Origin_Changed)));

One thing to be aware of is sometimes the code above throws an exception. The two cases where that happens are

1. The original metadata is a subclass of PropertyMetadata - I have seen FrameworkPropertyMetadata and UIPropertyMetadata. You just have to use the appropriate one in each case.

2. The dependency property is read only and you can't do anything about it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!