You are pretty much there. You can always apply a translucent color on top of your image under your text / content, but since you asked to change the whole image, here is what you can do:
In Visual Studio 2012, if you already have a button mainly in style / configured for what you want, right-click it, Edit Template -> Edit a Copy. Choose where you want to place the new style / template. This is similar to deciding where to place the CSS. It can be in the global file (App.xaml or StandardStyle.xaml) or in the header (page resources) or inline (management resources).
Below XAML may be overly simplified and does not work, but this is his idea:
<ControlTemplate x:Key="MyButton" TargetType="Button"> <Grid> <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="CommonStates"> <VisualState x:Name="Normal" /> <VisualState x:Name="PointerOver"> <Storyboard> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="HoverBackground" Storyboard.TargetProperty="Visibility"> <DiscreteObjectKeyFrame KeyTime="0" Value="Visible" /> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> <VisualState x:Name="Pressed"> <Storyboard> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PressedBackground" Storyboard.TargetProperty="Visibility"> <DiscreteObjectKeyFrame KeyTime="0" Value="Visible" /> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> [...] </VisualStateGroup> <VisualStateGroup x:Name="FocusStates"> [...] </VisualStateGroup> </VisualStateManager.VisualStateGroups> <Border x:Name="Border" [...]> <Grid> <Image Source="[...]" Stretch="None" /> <Image x:Name="HoverBackground" Source="[...]" Visibility="Collapsed" /> <Image x:Name="PressedBackground" Source="[...]" Visibility="Collapsed" /> <ContentPresenter x:Name="ContentPresenter" Content="{TemplateBinding Content}" ContentTransitions="{TemplateBinding ContentTransitions}" ContentTemplate="{TemplateBinding ContentTemplate}" Margin="{TemplateBinding Padding}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" [...]/> </Grid> </Border> [...] </Grid> </ControlTemplate>
Now you can put your 3 images in 3 <Image>
tags, and since the ContentPresenter is on top, when you use a template with <Button Template="{StaticResource MyButton}">
, you can put the content in it and it will appear on top of your background form. Or you can just have a fully graphic button with images.
source share