Question

I want my WPF application to be skinnable, by applying a certain XAML template, and the changes to be application wide, even for dynamic controls or controls that aren't even in the visual/logical tree.

What can I use to accomplish this type of functionality? Are there any good resources or tutorials that show how this specific task can be done?

Was it helpful?

Solution

The basic approach to take is using resources all through your application and dynamically replacing the resources at runtime.

See http://www.nablasoft.com/alkampfer/index.php/2008/05/22/simple-skinnable-and-theme-management-in-wpf-user-interface/ for the basic approach

OTHER TIPS

The replacing of resource will work but I found "structural skinning" to be more powerfull! Read more about it on CodeProject...

http://www.codeproject.com/KB/WPF/podder1.aspx

I have found the way to apply generic templates to all controls without using template keys. The solution is to use the type of the control as the Style key.

Example:

 <Application.Resources>
    <Style x:Key="{x:Type Button}" TargetType="{x:Type Button}">
        <Setter Property="Button.Background" Value="CornflowerBlue"/>
        <Setter Property="Button.Template">
            <Setter.Value>
                <ControlTemplate x:Name="MyTemplate">
                    ...
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</Application.Resources>

here the Style key is x:Key="{x:Type Button}", so the style will be applied to all controls of type button without the control declaring the Style property to be a static or dynamic resource.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top