Tag Archives: WPF

Setup visual style for WPF applications

Maybe you’re facing the same problem with me: WPF applications cannot use Windows Visual Style by default.
If you want a solution, follow these steps:

  1. Download this & unpack: Link.
  2. Add the “application.manifest” file to your wpf project in VisualStudio.
  3. Right click on the project in “Solution Explorer”, select “Properties”.
  4. Choose “Application” tab, in the “Resource” groupbox, select “Icon & manifest”, then select “application.manifest” on manifest combobox.
  5. Save all & build application, run it!

 

WPF in action: Dynamically set style for control

For example, I have a xaml like this:

<TabItem Header="Tab1" Style="{DynamicResource TabItemWithButton}">

I want create a new tab dynamically, & set style to “TabItemWithButton”, I will use this code:

newTab.SetResourceReference( TabItem.StyleProperty, "TabItemWithButton" );

Simple!

Actually, you can use SetResourceReference method to set many dependency properties, explore it!