未从App.xaml应用WPF样式

时间:2013-05-18 23:51:19

标签: wpf visual-studio-2010

我正在寻找将样式应用于所有WPF控件,例如在HTML中可以用CSS完成的操作。

这是我第一次涉足WPF,我收集了我需要在App.xaml中执行此操作。以下就是我所拥有的。

我已尝试TargetType="{x:Type TabItem}"TargetType="TabItem"

我所定义的任何风格都没有被应用。

的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>

1 个答案:

答案 0 :(得分:2)

 <Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Style.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>