Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When overriding WPF templates do I have to override each theme's template separately?

I have a requirement to change a very small part of the WPF ComboBox's template.

If I take a copy of the existing template for the Luna theme and make the change it all works fine initially. But if the user has a different theme, my ComboBox retains it's custom theme, (Which is obviously based on Luna) so looks out of place.

Is there any way of overriding just parts of a template so the majority of the template still respects the windows theme?

I notice that parts of the template define an mwt namespace with an explicit reference to Luna:

xmlns:mwt="...blah blah...=PresentationFramework.Luna"

perhaps there is some way to have this mwt namespace refer to the current theme rather than specifically the Luna one?

Or do I have to provide a custom copy of the template for each theme? And what happens if MS creates a new theme, will I then have to update my template to support it?

(The bit I am changing just relates to the TextBlock displayed when the combo box is closed. I'm not changing the dropdown or the button. Ideally I would just override the SelectionBoxItemTemplate on the ComboBox, but this is readonly, so as far as I can tell I have to override the whole control template to make any changes.)

[Related question, but no answers: Adjust a Control Template and still respect the Theme of the OS?]

like image 288
Simon P Stevens Avatar asked Mar 25 '10 12:03

Simon P Stevens


1 Answers

One thing to keep in mind is that once you create a ControlTemplate for you control, you are replacing the entire ControlTemplate.

From: http://msdn.microsoft.com/en-us/library/ms745683.aspx

What I gather from that is no, there is no way to replace portions of a template. The template is considered a single unit. However, there may be ways to customize your template to allow changes via styles (which can be based on other styles).

If MS makes a new theme, then you will have to update your own custom control templates to implement a similar theme. Remember, you're replacing, not enhancing the control template.

like image 67
Ed Gonzalez Avatar answered Oct 05 '22 15:10

Ed Gonzalez