在Win7上应用经典主题不适用于样式?

时间:2013-11-11 20:46:45

标签: wpf

我正在尝试在Win 7上运行的wpf应用中应用经典主题。我的代码基于以下帖子:Windows 7 theme for WPF?

一般来说上面的作品除了样式。也就是说,如果我应用在Resources中定义的样式,则经典主题将替换为Win7上的任何默认主题。例如,我可以直接在一个按钮中设置字体大小,边距和宽度,似乎工作(即按钮具有经典外观)。但是,如果我将上述属性移动到样式然后将样式应用于同一个按钮,按钮的经典外观就会消失 - 字体大小,边距和宽度都会被尊重(即样式肯定会应用)。

有人可以给我一些指针/解决方法来解决这个问题吗? 感谢。

在第一个按钮后面的示例中忽略经典主题。

    <Application x:Class="Navigation.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>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/PresentationFramework.classic, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL;component/themes/Classic.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

<Window x:Class="Navigation.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <Style x:Key="myButton" TargetType="{x:Type Button}">
            <Setter Property="Margin" Value="4,0,0,0" />
            <Setter Property="MinWidth" Value="70" />
            <Setter Property="FontSize" Value="16" />
        </Style>
    </Window.Resources>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <Button Grid.Row="0" Grid.Column="0" Content="First" Command="{Binding FirstCommand}" Style="{StaticResource myButton}"/>
        <Button Grid.Row="0" Grid.Column="1" Content="Next" Command="{Binding NextCommand}" FontSize="16" Margin="4,0,0,0" MinWidth="70"/>
        <Button Grid.Row="0" Grid.Column="2" Content="Dialog" Command="{Binding DialogCommand}" FontSize="16" Margin="4,0,0,0" MinWidth="70"/>

        <Frame Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" x:Name="_mainFrame" />
    </Grid>
</Window>

0 个答案:

没有答案