0

I'm looking to apply styling to all WPF controls like what can be done with CSS in HTML.

This is my first dabbling in WPF and I've collected that I need to do this in App.xaml. Below is what I've got.

I've tried TargetType="{x:Type TabItem}" and TargetType="TabItem".

None of the styles I've defined are being applied.

App.xaml

<Application x:Class="VMware_Lab_Manager_Desktop.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"> <Application.Resources> <ResourceDictionary Source="Styles.xaml"></ResourceDictionary> </Application.Resources> </Application> 

Styles.xaml

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Style TargetType="{x:Type TabControl}"> <Setter Property="Background"> <Setter.Value> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FF464646" Offset="0" /> <GradientStop Color="#FF2D2D2D" Offset="0.5" /> <GradientStop Color="#FF141414" Offset="1" /> </LinearGradientBrush> </Setter.Value> </Setter> </Style> <Style TargetType="{x:Type TabItem}"> <Setter Property="Background"> <Setter.Value> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FF464646" Offset="0" /> <GradientStop Color="#FF2D2D2D" Offset="0.5" /> <GradientStop Color="#FF141414" Offset="1" /> </LinearGradientBrush> </Setter.Value> </Setter> <Setter Property="BorderBrush"> <Setter.Value> <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5"> <GradientStop Color="Black" Offset="0" /> <GradientStop Color="#FF464646" Offset="1" /> </LinearGradientBrush> </Setter.Value> </Setter> </Style> <Style TargetType="{x:Type Window}"> <Setter Property="Background"> <Setter.Value> <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5"> <GradientStop Color="#FF2D2D2D" Offset="0.5" /> <GradientStop Color="#FF141414" Offset="0" /> <GradientStop Color="#FF464646" Offset="1" /> </LinearGradientBrush> </Setter.Value> </Setter> </Style> </ResourceDictionary> 

MainWindow.xaml

<Window x:Class="VMware_Lab_Manager_Desktop.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="456" Width="803" Padding="0" Margin="0"> <TabControl HorizontalAlignment="Stretch" Margin="0" Padding="0" Name="tabControl1" VerticalAlignment="Stretch" BorderThickness="0" TabStripPlacement="Bottom"> <TabItem Name="tabItem1" Header="..."> <WebBrowser HorizontalAlignment="Stretch" Name="webBrowser1" Margin="0" VerticalAlignment="Stretch" Source="http://www.msdn.com/" /> </TabItem> <TabItem Header="+" /> </TabControl> </Window> 
3
  • Where in your solution is Style.xaml located, the path in your App.xaml usally contains the namespace and location of the resourceDictionary to merge, e.g <ResourceDictionary Source="/VMware_Lab_Manager_Desktop;component/Themes/Style.xaml" /> Commented May 19, 2013 at 0:15
  • Styles.xaml is at the same level in solution explorer as App.xaml and MainWindow.xaml. I've aso tried putting the ResourceDictionary directly in App.xaml. Commented May 19, 2013 at 0:21
  • Have you tried using MergedDictionary? I will post below because it wont fit in comment :) Commented May 19, 2013 at 0:23

1 Answer 1

2
 <Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="Style.xaml" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources> 
Sign up to request clarification or add additional context in comments.

5 Comments

No dice. I think I'm missing something else.
Strange, styles seem to show in the Visual Studio editor preview, but don't when the app is run. I put the project on github here.
Sry, looks like some styles are there. For some reason the window and selected tab backgrounds aren't showing up.
This solved the window style not showing up.
This solved the selected tab background issue. Guess it really was working but these other issues tricked me :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.