I'm trying to create a "hover" effect when the user touches their finger down on to a button. When that happens I would like to background color of the button to change - and then when they move it away it changes back to the original color.
My code for the whole button is below
<Button x:Name="btnService" HorizontalAlignment="Center" Tag="{Binding Tag}" Command="{Binding DataContext.ConnectServiceCommand, ElementName=LayoutRoot}" CommandParameter="{Binding Tag}">
<Button.Template>
<ControlTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="350" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="64" />
<RowDefinition Height="10" />
</Grid.RowDefinitions>
<Border IsTapEnabled="True" CornerRadius="0" BorderBrush="Transparent" BorderThickness="0" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Grid.Row="0" Grid.Column="1">
<TextBlock Style="{StaticResource BodyTextBlockStyle}" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="{StaticResource accentForeground}" Text="{Binding NameUpper}" />
<Border.Style>
<Style TargetType="Border">
<Setter Property="Background" Value="{StaticResource bodyAccent}" />
</Style>
</Border.Style>
</Border>
</Grid>
</ControlTemplate>
</Button.Template>
</Button>
What I can't get working is the trigger as it doesn't seem to exist - I know normal WPF XAML apps have something like <Trigger Property="Border.IsMouseOver" Value="True">
Is there something like this for Windows Phone 8.1 apps?
Edit - Code added with VSManager
<Button x:Name="btnService" HorizontalAlignment="Center" Tag="{Binding Tag}" Command="{Binding DataContext.ConnectServiceCommand, ElementName=LayoutRoot}" CommandParameter="{Binding Tag}">
<Button.Template>
<ControlTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="350" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="64" />
<RowDefinition Height="10" />
</Grid.RowDefinitions>
<Border IsTapEnabled="True" CornerRadius="0" BorderBrush="Transparent" BorderThickness="0" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Grid.Row="0" Grid.Column="1">
<TextBlock Style="{StaticResource BodyTextBlockStyle}" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="{StaticResource accentForeground}" Text="{Binding NameUpper}" />
<Border.Style>
<Style TargetType="Border">
<Setter Property="Background" Value="{StaticResource bodyAccent}" />
</Style>
</Border.Style>
</Border>
</Grid>
</ControlTemplate>
</Button.Template>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Pressed">
<Storyboard>
<PointerDownThemeAnimation Storyboard.TargetName="Grid"/>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="Border">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource bodyAccentAlt}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Button>
In the default Button style, there are some predefined visual states. In those visual states, you can define what happens when the Button is pressed
In
is what happens when the Button is pressed. You can easily define the background of the Border element
The important part is the ObjectAnimationUsingKeyFrames targeting Background property of the element with the name "Border"
And Button style is applied like this: