Reputation: 1
I am creating a WP7 app using Silverlight+XNA. In that, I'm using an image as background of a button(Silverlight element) and whenever I press the button, a white background appears. How can I get rid of it? It seems like the default property of the button.
Upvotes: 0
Views: 2097
Reputation: 31
Setting the button's ClickMode to Press will disable the effect
<Style TargetType="Button">
<Setter Property="ClickMode" Value="Press"/>
</Style>
Upvotes: 3
Reputation: 145
there are some existing threads for this question :
I implemented this, the way @thongaduka suggested. Check the complete implementation below.
<StackPanel Height="auto" HorizontalAlignment="Left" Margin="0,0,0,0" Name="stackPanel1" VerticalAlignment="Top" Width="auto" >
<StackPanel.Resources>
<Style x:Key="ButtonTemplate_ok" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="MouseOver">
<Storyboard>
<ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00" Storyboard.TargetProperty="Background" Storyboard.TargetName="hoverbutton">
<DiscreteObjectKeyFrame KeyTime="00:00:00">
<DiscreteObjectKeyFrame.Value>
<ImageBrush ImageSource="/StickGameSlX;component/Images/buttons/ok_pressed.png"/>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="FocusStates">
<VisualState x:Name="Focused"/>
<VisualState x:Name="Unfocused"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Border x:Name="hoverbutton">
<Border.Background>
<ImageBrush ImageSource="/StickGameSlX;component/Images/buttons/ok_unpressed.png"/>
</Border.Background>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</StackPanel.Resources>
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" >
<Button Style="{StaticResource ButtonTemplate_ok}" Content="OK" HorizontalAlignment="Center" Margin="546,296,198,130" Name="button1" VerticalAlignment="Center" Click="button1_Click" Width="57" Height="53" BorderBrush="White" Foreground="Black"/>
</Grid>
</StackPanel>
Upvotes: 1
Reputation: 59
You should use the expression blend to edit the style of your button.e.g you can edit the background or border brush when your button is in pressed state.
Upvotes: 0
Reputation: 2012
You have to create a style for button . Change the properties for button for each visual states. Like set background image properties for differetn states like pressed, normal ,etc. And apply that style for your button. Microsoft Expression Blend will help you do that in a few simple steps.
Upvotes: 0