XAML UserControl 中元素的覆盖方法? [英] Overriding method of an element within a XAML UserControl?

查看:43
本文介绍了XAML UserControl 中元素的覆盖方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Silverlight 用户控件,它没有模板,也不需要模板,因为它只是一个带有 RectangleGeometry 的路径,可通过代码调整大小.现在我们的设计已经在路径的工具提示中添加了一个模板,我希望能够为控件的用户提供一种方法来更改此模板一部分的布局.如果模板是控件整体的一部分,我可以简单地覆盖控件的 OnApplyTemplate 方法并获取对我想要修改的部分的引用.但由于控件没有模板,因此永远不会调用控件代码隐藏中的重写方法.

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.

有什么方法可以覆盖控件代码中模板化元素的 OnApplyTemplate 方法吗?

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

推荐答案

什么是基类.如果基础类不支持模板,则不能覆盖 OnApplyTemplate.我认为您最好在设置值时更改工具提示样式(因为它无论如何都不太可能出现).

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).

有什么理由不能在路径改变时只执行 GetTemplateChild 吗?这在一生中应该足够晚了.

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

这篇关于XAML UserControl 中元素的覆盖方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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