Adjust a Control Template and still respect the Theme of the OS? - wpf

In WPF how do I modifiy the template for a standard control in a way that it will respect the current Theme of the Operating System later on? If I just "edit a copy" of the template in blend, it will just give me the template of the currently running theme. Is this correct? So when I apply the modified template and run the app on different themes it will always look the same.
For custom controls and even for data templates the problem is similar. How do I provide a template that respects all possible themes of the OS?

I don't think this is possible. If you create a template for a control you are replacing the entire control template.
You can use styles to just configure exposed properties, but if you change the template, you are no longer related to the theme. You can create a separate override of the template for each theme, but you would have to define each explicitly and if Microsoft created a new theme you would have to create a new template to match it.
See my own related question - When overriding WPF templates do I have to override each theme’s template separately?

Related

Edit WPF styles for a "designer"

We have a designer that did a whole concept of GUI for our next WPF application.
If we are able to provide him a "user friendly" way to edit styles, he would have done it by itself.
He only has to edit colors, and small things like Margin, default fonts, ...
Naturally, I tought that Blend would be the solution, but I admit I'm struggling:
Blend allow us to edit the template, but we don't really want to change the whole template, just some color around. We made a small dummy app that has all the controls required to be themed, we edit template in a dedicated theme file, but I can't find how to have the same template applied to every control(e.g. button) in our application
We use DevExpress as library, and it appears that most of their component are composed of a lot of subcomponent(for which I cannot just right-click then edit template). Plus it seems that the devExpress theme have the priority over the templates changes(tested by changing background colors by example)
As a pure developer I would create a "style" that would be applied on all controls of a specific type in our application, but I can't see how to create and edit them in blend?
What approach would you take?
You want to use DevExpress Theme Editor. It will allow you to edit all used DevExpress themes in your application. It has a friendly UI which should be usable by your designer.
Another approach is probably not so friendly for your designer but you can also manually override DevExpress themes with your extended ones (require XAML). I am not sure about the controls but that way you can for sure modify brushes.

Resource Dictionaries in a Silverlight Assembly?

I've just begun dabbling in putting together a set of controls as assemblies and I'm working on default styling. What I currently have is a UserControl in a project (thanks Reed!) and I'm able to bring that into another project via reference. I plan to add more controls over time to build something of an SDK.
I currently have some hooks that look for resources in the hosting application which either apply the resources to their respective properties, or style out the control via hard coded defaults.
Is it possible to set up resource dictionaries within the project containing the UserControls so they can use those references as the default, instead of hard coding? If so, how do I target them?
(I have a ResourceDictionary set up within the same project as the controls: Resources>Dictionaries>Colors.xaml)
Thanks in advance!
E
You should really look at creating custom templated controls in library rather than derivatives of UserControls. This will allow projects that reference your library to specify an alternative default style for you controls in the same way as we can for the controls in Microsofts own SDK.
The Creating a New Control by Creating a ControlTemplate topic on MSDN is good starter.
I think this is a better explanation, but i'm trying on a desktop application and i got the same problem.
XamlParseException: Failed to create a 'System.Type' from the text 'local:CustomerEntity'
If I'm undestanding correctly you want to create the file "generic.xaml" in the folder "Themes". However, I don't believe automatic styling works with UserControl only with Control. Generally if you trying to make a control that can be stylized and retemplated you want to inherit from Control and not UserControl.

Multiple Control Templates for a custom control in Silverlight

I am creating a custom control. The contents of the control will differ a lot when in different visual states.
Can I to achieve the above, apply different control templates to the same custom control? That is define more than one control template for a custom control? If not, any clues as to how I can do this, without have as many custom/user controls as there are states?
You could define visual states inside a single ControlTemplate and also transitions between those states. Look for 'VisualStateManager'.

Does overriding default style/controltemplates break theming?

When I override the default style/controltemplate of a standard WPF control in blend using "Edit a Copy" without modifying it (just creating a local copy of if), will this already break theming in some scenarios? In other words, do different themes provide differnt controltemplate- and/or styledefinitions for the standard controls? How can I make sure that my styles/controltemplates respect theming?
Yes, this breaks theming;
Yes, different themes provide different controls styles. If you have MS Blend you can find them in Blend's folder (e.g. in C:\Program Files\Microsoft Expression\Blend 3\SystemThemes\Wpf )
To respect theming, you should also create one style per theme for your control. There are many resources out there on custom control and themes support. Just to mention one: WPF: Changing control style based on the system theme
As a developer you want to author your controls in terms of their functionality. Use default control styles everywhere. Then let the pro's handle the graphic design aspect of it. If you override a control's ControlTemplate you are busy with theming already.
If you do muck around with ControlTemplates try and keep with the standard approach, otherwise once the graphic designer starts working on the application he/she's going to swear at you :)
Themes are collections of styles that target individual controls and redefine their look-and-feel. Any Control for which you've provided a ControlTemplate will either not have it applied or won't be consistent with the theme-pack (depending on whether you access the theme by x:Name or by Type)
If you override DataTemplates, you are fine however. This you can safely do without worrying about theming interference.

What is the best practice for creating RE-USABLE control templates in Silverlight

What is the best practice for creating re-usable control templates.
For example. I want to start with the standard checkbox and modify its template for re-use accross multiple future projects.
I understand how to modify the template in Blend, but it always wants to save the template to App.xaml of the current project or to the parent control where I first placed the checkbox.
Ideally I would like some soft of ControlLibrary that contains all my custom controls AND custom templates (modified templates of existing controls)
-Jeff
Implicit Style Manager might be helpful.
The Silverlight controls team and others have been blogging a bit recently about ISM which allows alternative style sets to be applied across the board to standard controls. Try Jesse Liberty's blog or Mehdi Slaoui Andaloussi's blog
HTH
I don't think you can have a ControlTemplate as a separate entity, without it being attached to a Control. For your control library you can create custom controls that have the appropriate custom templates and reuse the controls.

Resources