2014-08-27 52 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