2012-08-17 90 views
0

我有一個形象Silverlight的按鈕背景圖像刷

http://savepic.su/2317454.htm

但wnen我嘗試設置按鈕的背景像

<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> 

我有
http://savepic.su/2309262.htm
在所有瀏覽器的圖像..
我該如何設置正常圖像到按鈕的背景?

以及我如何設置另一個圖像,以在xaml中顯示此按鈕的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> 

我認爲這是一個最好的解決辦法,因爲你可以顯示你想要什麼對另一個國家和控制可見的影響。