2014-08-27 53 views
-1

我一直在WPF工作了几天,并且我已经在photoshop中预先设计了我的项目。现在,我正在去WPF开发的路上。但是,问题如下:是否有阻止Windows主题的方法?我的意思是,例如当创建一个按钮时,它会按照我想要的方式进行样式设置,但悬停/点击事件仍会覆盖设计,最终看起来完全不合适。在一个非常糟糕的方式。 我想,我可能要找的是一个相当于在CSS中可访问的通配符...如何删除Windows主题的样式?

回答

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> 

+0

tyvm!像魅力一样工作。 – 2014-08-29 16:06:59