如何删除Windows主题的样式?

时间:2014-08-27 17:45:58

标签: c# wpf

我已经和WPF一起工作了几天,我已经在photoshop中预先设计了我的项目。现在,我正在前往WPF开发。但问题是:有没有办法阻止Windows的主题?我的意思是,例如,在创建一个按钮时,它的样式将按照我想要的方式设置,但悬停/点击事件仍会覆盖设计,最终看起来完全是邪恶的。以一种非常糟糕的方式。 我想,我可能正在寻找的是与css中可访问的通配符相当的...

2 个答案:

答案 0 :(得分:1)

我理解你的问题所以如果你想根据你做一个完整的自定义按钮,那么你可以使用按钮的Template属性。

您可以在Windows资源部分编写一些样式代码。

<Window x:Class="DataBinding.ButtonTemplating"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="ButtonTemplating" Height="300" Width="300">
<Window.Resources>
    <Style TargetType="{x:Type Button}">
        <Setter Property="Background" Value="#373737" />
        <Setter Property="Foreground" Value="White" />
        <Setter Property="FontSize" Value="15" />
        <Setter Property="SnapsToDevicePixels" Value="True" />

        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Button}">
                    <Border CornerRadius="4" Background="{TemplateBinding Background}">

                            <ContentPresenter x:Name="MyContentPresenter" Content="{TemplateBinding Content}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,0,0" />

                    </Border>

                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Background" Value="#E59400" />
                            <Setter Property="Foreground" Value="White" />

                        </Trigger>

                        <Trigger Property="IsPressed" Value="True">
                            <Setter Property="Background" Value="OrangeRed" />
                            <Setter Property="Foreground" Value="White" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</Window.Resources>
<Button Width="200" Height="50" VerticalAlignment="Top">WPF</Button>

答案 1 :(得分:0)

是的,您可以通过应用自己的控件模板来覆盖任何Windows主题。悬停/点击事件是这些模板的一部分。

如果您将控件模板作为资源的一部分,则可以在所有控件中重复使用它们。

可以在此处找到默认模板:http://msdn.microsoft.com/en-us/library/aa970773(v=vs.110).aspx

按钮样式和模板可在此处找到:http://msdn.microsoft.com/en-us/library/ms753328(v=vs.110).aspx