Overriding method of an element within a XAML UserControl?

隐身守侯 提交于 2019-12-25 03:18:22

问题


I have a Silverlight user control that has no template and does not need one as it is simply a path with a RectangleGeometry that is resized by code. Now our designed has added a template to the tooltip of the path and I want to be able to provide a method for users of the control to change the layout of a portion of this template. If the template was part of an overall one for the control I could simply override the control's OnApplyTemplate method and grab a reference to the section I want to modify. But as the control has no template the overridden method in the control's code-behind is never called.

Is there some way I can override the OnApplyTemplate method for the templated element in the control's code behind?


回答1:


What is the base-class. You can't override OnApplyTemplate if the underlying class doesn't support templates. I think you'd be best to just change the tooltip style when the value is set (as its unlikely to show up anyway).

Any reason you can't just do GetTemplateChild as the path changes? That should be late enough in the lifetime.



来源:https://stackoverflow.com/questions/1497842/overriding-method-of-an-element-within-a-xaml-usercontrol

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