【发布时间】:2011-05-18 08:47:49
【问题描述】:
.
大家好,
我们能否编写我们的自定义控件,以便稍后我们可以重新模板化它部分?意思是,在不替换整个 ControlTemplate 的情况下,我们想要更改/覆盖 一些它的外观和感觉?
当然,一种方法是:从 generic.xaml 中复制 ControlTemplate 代码,部分修改它的外观,然后在您的 xaml 中使用它,如下所示:
<MyCustomControl>
<MyCustomControl.Template>
<ControlTemplate>
<!-- paste the copied and modified code from generic.xaml here-->
</ControlTemplate>
</MyCustomControl.Template>
<!--other code-->
</MyCustomControl>
但这种方法的问题在于,我们使 xaml 过于冗长。我真的不喜欢它。我正在寻找一些解决方案,可以避免污染我使用自定义控件的 xaml。
感谢期待!
.
【问题讨论】:
标签: wpf silverlight xaml custom-controls controltemplate