When overriding WPF templates, do I need to override each theme template separately?

I have a requirement to modify a very small part of the WPF ComboBox template.

If I take a copy of the existing template for the Luna theme and make a change, everything will work fine initially. But if the user has a different theme, my ComboBox retains its custom theme (which is obviously based on Luna), so it looks out of place.

Is there a way to override only parts of the template, so most templates are still Windows related?

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

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

maybe there is a way for this mwt namespace to refer to the current topic, and not just to Luna one?

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

(the bit that I change only refers to the TextBlock displayed when the combo box is closed. I do not change the drop-down list or button. Ideally, I would just override SelectionBoxItemTemplate with a ComboBox but this is read-only, so as far as I can tell, I you need to redefine the entire management template to make any changes.)

[Related question, but no answers: Customize the management template and still respect the OS theme? ]

+4
source share
1 answer

Keep in mind that once you create a ControlTemplate for you to control, you replace the entire ControlTemplate.

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

What I get from this is no, there is no way to replace parts of the template. The template is considered as a whole. However, there may be ways to customize your template to allow changes through styles (which may be based on other styles).

If MS creates a new theme, you will need to update your own custom management templates to implement a similar theme. Remember that you are replacing without increasing the control pattern.

+5
source

Source: https://habr.com/ru/post/1305091/


All Articles