.
Hello guys,
Can we write our custom controls in such a way that later on we can re-template it partially? Means, without replacing the entire ControlTemplate, we want to change/override some of it's look and feel?
One way, of course, is this : copy the ControlTemplate code from generic.xaml, modify it's look and feel partially, and use it in your xaml, as shown below:
<MyCustomControl>
<MyCustomControl.Template>
<ControlTemplate>
<!-- paste the copied and modified code from generic.xaml here-->
</ControlTemplate>
</MyCustomControl.Template>
<!--other code-->
</MyCustomControl>
But the problem with this approach is that, we make our xaml too verbose. And I seriously don't like it. I'm looking for some solution that may save me from polluting the xaml where I'm using my custom control.
Thanks in anticipation!
.
I agree with most of what Martin says about ControlTemplates being pretty much an all or nothing thing in WPF and I was pretty frustrated myself when I came to this conclusion.
If your writing your own custom control however you can make it more flexible why composing or offering the ability to template pices of the control. For an example you can look at the newer WPF DataGrid control which has the ability to template different pieces of the control. Other headered content controls often have a separate template for the content and the header portion of the control making it possible to replace one but not the other.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With