C# 如何在单击按钮时删除突出显示
当点击一个按钮时,它会以用户为windwos手机设备设置的主题颜色高亮显示几秒钟。应该调用什么方法来克服这种行为。我尝试使用MouseEnter并将背景设置为白色,但它不起作用C# 如何在单击按钮时删除突出显示,c#,xaml,windows-phone-7,windows-phone-8,C#,Xaml,Windows Phone 7,Windows Phone 8,当点击一个按钮时,它会以用户为windwos手机设备设置的主题颜色高亮显示几秒钟。应该调用什么方法来克服这种行为。我尝试使用MouseEnter并将背景设置为白色,但它不起作用 System.Windows.Media.SolidColorBrush whiteBrush = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(255, 255, 255, 255));
System.Windows.Media.SolidColorBrush whiteBrush = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(255, 255, 255, 255));
signIn.Background = whiteBrush;
有人能帮忙吗?你必须使用。这允许您使用VisualStateManager并控制控件在任何显示点(正常、悬停、按下、聚焦)的外观。这个主题非常冗长。不要使用单击事件,只需使用
MouseLeftButtonUp
和MouseLeftButtonDown
事件即可
当您当时按下按钮时,MouseLeftButtonDown
事件为fire,因此在此方法中,您可以使用
System.Windows.Media.SolidColorBrush whiteBrush = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(255, 255, 255, 255));
signIn.Background = whiteBrush;
在MouseLeftButtonUp
事件中,您可以设置正常的按钮颜色
希望它对您有用。这是您需要编辑的地方。相应地更改按下的标签
<phone:PhoneApplicationPage ...>
<phone:PhoneApplicationPage.Resources>
<Style x:Key="ButtonStyle1" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid Background="Transparent">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="MouseOver"/>
<VisualState x:Name="Pressed">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentContainer">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneBackgroundBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="ButtonBackground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneForegroundBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ColorAnimation Duration="0" To="Cyan" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" Storyboard.TargetName="ButtonBackground" d:IsOptimized="True"/>
</Storyboard>
</VisualState>
<VisualState x:Name="Disabled">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentContainer">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneDisabledBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="ButtonBackground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneDisabledBrush}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Border x:Name="ButtonBackground" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="0" Margin="{StaticResource PhoneTouchTargetOverhang}" Background="Black">
<ContentControl x:Name="ContentContainer" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Foreground="{TemplateBinding Foreground}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Padding="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</phone:PhoneApplicationPage.Resources>
<Grid x:Name="LayoutRoot" Background="Transparent">
<Button Content="Button" Style="{StaticResource ButtonStyle1}"/>
</Grid>
将它添加到页面并让我知道:)是的,这就是我要找的。。一吨。。它起作用了!非常感谢您的帮助:)