2012-08-17 3 views
0

나는 이미지를실버 버튼 배경 ImageBrush와

http://savepic.su/2317454.htm

을 가지고 있지만 내가

<UserControl x:Class="System.Windows.Controls.UserControl" xmlns="http://schemas.microsoft.com/client/2007" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
<Button x:Name="plus_button" Width="30" Height="25"> 
    <Button.Background> 
     <ImageBrush AlignmentY="Top" Stretch="None" ImageSource="plus_unhover.jpg"></ImageBrush> 
    </Button.Background> 
</Button> 
</UserControl> 

처럼 버튼의 배경을 설정하려고 wnen 내가
http://savepic.su/2309262.htm
모든 브라우저에서 그 이미지를 가지고 ...
정상적인 이미지를 배경의 배경으로 설정할 수 있습니까?

어떻게 xaml에서이 버튼의 backgroun onmouseover 이벤트에 다른 이미지를 설정할 수 있습니까?

답변

1

나는 다음과 같이 버튼의 스타일을 사용

<Style x:Key="minusButtonStyle" TargetType="Button"> 
<Setter Property="ToolTipService.ToolTip" Value="Уменьшить масштаб графика, Ctrl + вниз" /> 
<Setter Property="Width" Value="35"/> 
<Setter Property="Template"> 
    <Setter.Value> 
    <ControlTemplate TargetType="Button"> 
    <Grid> 
    <vsm:VisualStateManager.VisualStateGroups> 
     <vsm:VisualStateGroup x:Name="CommonStates"> 
     <vsm:VisualState x:Name="Normal"/> 
     <vsm:VisualState x:Name="MouseOver"> 
     <Storyboard> 
     <DoubleAnimation Duration="0" Storyboard.TargetName="hoverImage" Storyboard.TargetProperty="Opacity" To="1"/> 
     </Storyboard> 
     </vsm:VisualState> 
     <vsm:VisualState x:Name="Pressed"> 
     <Storyboard> 
     <DoubleAnimation Duration="0" Storyboard.TargetName="pressedImage" Storyboard.TargetProperty="Opacity" To="1"/> 
     </Storyboard> 
     </vsm:VisualState> 
     <vsm:VisualState x:Name="Disabled"> 
     <Storyboard> 
     <DoubleAnimation Duration="0" Storyboard.TargetName="unactiveImage" Storyboard.TargetProperty="Opacity" To="1"/> 
     </Storyboard> 
     </vsm:VisualState> 
     </vsm:VisualStateGroup> 
     <vsm:VisualStateGroup x:Name="FocusStates"> 
     <vsm:VisualState x:Name="Focused"/> 
     <vsm:VisualState x:Name="Unfocused" /> 
     </vsm:VisualStateGroup> 
    </vsm:VisualStateManager.VisualStateGroups> 
    <Border x:Name="normalImage" Opacity="1"> 
     <Border.Background> 
     <ImageBrush AlignmentY="Top" Stretch="None" ImageSource="Images/minus_unhover.png" Opacity="1.0"></ImageBrush> 
     </Border.Background> 
    </Border> 
    <Border x:Name="hoverImage" Opacity="0"> 
     <Border.Background> 
     <ImageBrush AlignmentY="Top" Stretch="None" ImageSource="Images/minus_hover.png" Opacity="1.0"></ImageBrush> 
     </Border.Background> 
    </Border> 
    <Border x:Name="pressedImage" Opacity="0"> 
     <Border.Background> 
     <ImageBrush AlignmentY="Top" Stretch="None" ImageSource="Images/minus_pressed.png" Opacity="1.0"></ImageBrush> 
     </Border.Background> 
    </Border> 
    <Border x:Name="unactiveImage" Opacity="0"> 
     <Border.Background> 
     <ImageBrush AlignmentY="Top" Stretch="None" ImageSource="Images/minus_unactive.png" Opacity="1.0"></ImageBrush> 
     </Border.Background> 
    </Border> 
    <ContentPresenter x:Name="contentPresenter" Content="{TemplateBinding Content}"/> 
    </Grid> 
    </ControlTemplate> 
    </Setter.Value> 
</Setter> 
</Style> 

그리고 버튼에이 스타일을 적용 :

<Button x:Name="minus_button" Style="{StaticResource minusButtonStyle}" ClickMode="Release"></Button> 

난 당신이 당신이 원하는 것을 표시 할 수 있습니다 원인, 자사의 최고의 솔루션을 생각 다른 주에서는 볼 수있는 효과를 제어합니다.