I am creating an app for windows phone 8 and I want the button control to change colors of borderbrush, background, and foreground when pressed or tapped and when released to change back to its original colors. The problem is the phone uses its accent color when I click on any button in the app after the Tap event has been fired. I notice Tap
event is not what I'm looking for since, it changes the color correctly when tapped and doesn't change back when released. I also tried MouseLeftButtonDown
(pressed) and MouseLeftButtonUp
(released) and it didn't fire whatsoever. Is there a better way to easily change the button's color when pressed and back when released?
I looked at MSDN Network - UIElement Events but couldn't find anything else that fits.
XAML:
<Button Name="btnEmail"
Content="email"
HorizontalAlignment="Stretch"
Margin="0,10,0,0"
Grid.Row="4"
VerticalAlignment="Top"
Background="OrangeRed"
BorderBrush="OrangeRed"
Tap="btnEmail_Tap"
MouseLeftButtonDown="btnEmail_MouseLeftButtonDown"
MouseLeftButtonUp="btnEmail_MouseLeftButtonUp"
/>
C# Code:
private void btnEmail_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
btnEmail.BorderBrush = new SolidColorBrush(ColorNames.White.ToColor());
btnEmail.Background = new SolidColorBrush(ColorNames.White.ToColor());
btnEmail.Foreground = new SolidColorBrush(ColorNames.OrangeRed.ToColor());
}
private void btnEmail_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
btnEmail.BorderBrush = new SolidColorBrush(ColorNames.OrangeRed.ToColor());
btnEmail.Background = new SolidColorBrush(ColorNames.OrangeRed.ToColor());
btnEmail.Foreground = new SolidColorBrush(ColorNames.White.ToColor());
}
private void btnEmail_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
btnEmail.BorderBrush = new SolidColorBrush(ColorNames.White.ToColor());
btnEmail.Background = new SolidColorBrush(ColorNames.White.ToColor());
btnEmail.Foreground = new SolidColorBrush(ColorNames.OrangeRed.ToColor());
}