Sunday, August 29, 2010

WPF - Restricting a Specific Windows Theme

In this post we will discuss how we can target our applications to a particular Windows Theme. We will be restricting it to Royale theme.

First we need to add a reference of PresentationFramework.Royale.dll. Right click References and select "Add Reference".

The assembly should be available in .net tab:

After selecting this should be available in References folder:

After adding the reference, we should merge the resources in App.xaml.


Now we can design our views. The theme should be automatically applied to the controls used in the application.

<Window x:Class="WPFComboBoxEditable.Window10"
DataContext="{DynamicResource Data}"
Title="Window7" >
<x:Array x:Key="Data" Type="{x:Type sys:String}">

<RowDefinition Height="100" />
<RowDefinition Height="100" />
<RowDefinition Height="100" />
<RowDefinition Height="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="200" />
<ColumnDefinition Width="*" />
<TextBox Grid.Row="0" Grid.Column="1"></TextBox>
<Button Grid.Row="1" Grid.Column="1">testttt</Button>
<ComboBox Visibility="Visible" Grid.Column="1"
Name="comboBox1" ItemsSource="{Binding}"

When we run the application, this should appear as follows:

If user personalize theme settings then those changes would also be updated to the application.

No comments: