我正在使用C#/ VS2013编写Windows应用商店应用
当我修改按钮图像样式以在鼠标指针悬停在按钮上时创建效果时,我使用以下内容:
<Style x:Key="ButtonStyle" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Image Source="/button_enabled.png" x:Name="Image" Height="50" >
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal">
<Storyboard Storyboard.TargetName="Image" Storyboard.TargetProperty="Source">
<ObjectAnimationUsingKeyFrames>
<DiscreteObjectKeyFrame KeyTime="0" Value="/button_enabled.png"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="PointerOver">
<Storyboard Storyboard.TargetName="Image" Storyboard.TargetProperty="Source">
<ObjectAnimationUsingKeyFrames>
<DiscreteObjectKeyFrame KeyTime="0" Value="/button_over.png"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Pressed">
<Storyboard Storyboard.TargetName="Image" Storyboard.TargetProperty="Source">
<ObjectAnimationUsingKeyFrames>
<DiscreteObjectKeyFrame KeyTime="0" Value="/button_click.png"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Image>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
当我使用鼠标导航光标时,这完全正常。
但是,当我使用触摸屏点击按钮(而不是使用鼠标点击按钮)时,它总是需要单独2次点击才能注册动作。
如果我删除了PointerOver部分,那么一切正常(鼠标点击和触摸/点击),但是在使用鼠标时我会失去鼠标悬停效果。
任何人都有关于为什么会这样的想法?这是PointerOver属性中的错误吗?
的更新
这是按钮实例化的方式:
<Grid Grid.Column="1">
<Button Style="{StaticResource ButtonStyle}" Tag="Style1" HorizontalAlignment="Right" Margin="10,0,10,0" Click="Btn_Click" PointerReleased="Btn_Released" IsEnabled="True"/>
</Grid>