大家好,
我们能否以这样的方式编写自定义控件,以便稍后可以部分地重新模板化它?也就是说,在不替换整个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。
谢谢您的期待!