2016-06-28 4 views
1

다음 XAML 코드를 작성했습니다. 단추 위로 마우스를 가져 가면 단추의 색을 변경하는 스타일 코드가 추가되었습니다. 그러나 버튼 위에 마우스를 가져 가면 테두리 효과가 있지만 배경은 빨간색으로 변경되지 않습니다. 제발 조언.단추 위로 마우스를 가져 가면 단추 색상이 변경되지 않습니다.

<Window.Resources> 
       <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" /> 
       <Style x:Key="MyButtonStyle" TargetType="Button"> 
        <Setter Property="OverridesDefaultStyle" Value="True"/> 
        <Setter Property="Template"> 
         <Setter.Value> 
          <ControlTemplate TargetType="Button"> 
           <Border Name="border" 
            BorderThickness="1" 
            BorderBrush="DarkGray" 
            Background="{TemplateBinding Background}"> 
            <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" /> 
           </Border> 
           <ControlTemplate.Triggers> 
            <Trigger Property="IsMouseOver" Value="True"> 
             <Setter TargetName="border" Property="BorderBrush" Value="Black" /> 
             <Setter Property="Foreground" Value="Red"/> 
            </Trigger> 
           </ControlTemplate.Triggers> 
          </ControlTemplate> 
         </Setter.Value> 
        </Setter> 
       </Style> 
    </Window.Resources> 

<Button Style="{StaticResource MyButtonStyle}" Content="Install" Command="{Binding InstallCommand}" Visibility="{Binding InstallEnabled, Converter={StaticResource BooleanToVisibilityConverter}}" Margin="150,30,30,22" Width="118" BorderBrush="#FF252424" FontSize="18" FontWeight="Bold" Foreground="White" FontFamily="Segoe UI Light" FontStretch="ExtraExpanded" Background="#FF4F4F4F"/> 

답변

1

에 코드를 거의 수행, 작업이다가 완료하기 위해 다음

    당신은 스타일을 결합하는
  • , 그래서 버튼과 함께 추가 스타일을 지정할 필요를가 추가 필요한 경우 스타일.
  • 그런 다음, 세터의 버튼 태그에서 BorderBrush, ForegroundBackground
  • 추가 "배경"속성을 제거 응용 프로그램을 실행하고 변경이처럼 보이는 변화를

를 참조하십시오

<Style x:Key="MyButtonStyle" TargetType="Button"> 
    <Setter Property="OverridesDefaultStyle" Value="True"/> 
    <!--Sets the initial Foreground color--> 
    <Setter Property="Foreground" Value="White"/> 
    <!--Sets the initial Background color--> 
    <Setter Property="Background" Value="Gray"/> 

    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="Button"> 
       <Border Name="border" 
         BorderThickness="1"         
         Background="{TemplateBinding Background}"> 
      <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" /> 
       </Border> 
      <ControlTemplate.Triggers> 
        <Trigger Property="IsMouseOver" Value="True"> 
         <Setter TargetName="border" Property="BorderBrush" Value="Black" /> 
         <Setter Property="Foreground" Value="Red"/> 
         <Setter Property="Background" Value="Green"/> 
        </Trigger> 
      </ControlTemplate.Triggers> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 

버튼 컨트롤은 다음과 같습니다.

<Button Style="{StaticResource MyButtonStyle}" Content="Install" 
    Margin="150,30,30,22" Width="118" FontSize="18" 
    FontWeight="Bold" FontFamily="Segoe UI Light" FontStretch="ExtraExpanded" /> 
+0

wo rks! 감사 :) – mayooran