Xaml 按钮点击不是第一次被解雇[仅限windows 8.1/10平板电脑]

Xaml 按钮点击不是第一次被解雇[仅限windows 8.1/10平板电脑],xaml,mvvm,windows-store-apps,Xaml,Mvvm,Windows Store Apps,我正在编写一个带有3个状态按钮(正常、聚焦和按下)的windows通用应用程序示例 我的代码如下所示 现在我面临一个关于按钮点击的问题,当第一次按钮点击时,按钮点击事件并没有被触发。但在第一次点击后,它工作正常[问题只发生在windows平板电脑上,在台式机和笔记本电脑上工作正常] 这是已知的问题,还是我的代码有问题 CS XAML Generic.XAML <ResourceDictionary xmlns="http://schemas.microsoft.com/winf

我正在编写一个带有3个状态按钮(正常、聚焦和按下)的windows通用应用程序示例

我的代码如下所示

现在我面临一个关于按钮点击的问题,当第一次按钮点击时,按钮点击事件并没有被触发。但在第一次点击后,它工作正常[问题只发生在windows平板电脑上,在台式机和笔记本电脑上工作正常]

这是已知的问题,还是我的代码有问题

CS

XAML


Generic.XAML

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App5"
    xmlns:customControls="using:App5.CustomControl">

    <Style TargetType="customControls:CalcButton">
        <Setter
            Property="HorizontalAlignment"
            Value="Stretch" />
        <Setter
            Property="VerticalAlignment"
            Value="Stretch" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="customControls:CalcButton">
                    <Grid Width="{TemplateBinding Width}" Height="{TemplateBinding Height}">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualStateGroup.Transitions>
                                    <VisualTransition To="PointerOver"
                                                      GeneratedDuration="0:0:0" />
                                </VisualStateGroup.Transitions>
                                <VisualState x:Name="Normal" />
                                <VisualState x:Name="PointerOver">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames
                                            Storyboard.TargetName="ButtonBrush"
                                            Storyboard.TargetProperty="Source">
                                            <DiscreteObjectKeyFrame KeyTime="0:0:0"
                                                                    Value="{Binding HoverImage, RelativeSource={RelativeSource TemplatedParent}}" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Pressed">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames
                                            Storyboard.TargetName="ButtonBrush"
                                            Storyboard.TargetProperty="Source">
                                            <DiscreteObjectKeyFrame KeyTime="0:0:0"
                                                                    Value="{Binding PressedImage, RelativeSource={RelativeSource TemplatedParent}}" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Image x:Name="ButtonBrush" Source="{TemplateBinding NormalImage}" Stretch="Fill" />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style> 
</ResourceDictionary>

删除了ObjectAnimationUsingKeyFrames标记,并使用了DoubleAnimation标记。还将目标属性源更改为不透明。然后在指定的持续时间内使用更新图像

<VisualState x:Name="Normal">
   <Storyboard>
     <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="NormalButton"/>
   </Storyboard>
</VisualState>


Set=按下按钮。我们试过了。但是没有按预期工作,真的吗?嗯,没想到的是,稍后我们将不得不回到这一点来仔细观察,对此表示抱歉。
<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App5"
    xmlns:customControls="using:App5.CustomControl">

    <Style TargetType="customControls:CalcButton">
        <Setter
            Property="HorizontalAlignment"
            Value="Stretch" />
        <Setter
            Property="VerticalAlignment"
            Value="Stretch" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="customControls:CalcButton">
                    <Grid Width="{TemplateBinding Width}" Height="{TemplateBinding Height}">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualStateGroup.Transitions>
                                    <VisualTransition To="PointerOver"
                                                      GeneratedDuration="0:0:0" />
                                </VisualStateGroup.Transitions>
                                <VisualState x:Name="Normal" />
                                <VisualState x:Name="PointerOver">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames
                                            Storyboard.TargetName="ButtonBrush"
                                            Storyboard.TargetProperty="Source">
                                            <DiscreteObjectKeyFrame KeyTime="0:0:0"
                                                                    Value="{Binding HoverImage, RelativeSource={RelativeSource TemplatedParent}}" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Pressed">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames
                                            Storyboard.TargetName="ButtonBrush"
                                            Storyboard.TargetProperty="Source">
                                            <DiscreteObjectKeyFrame KeyTime="0:0:0"
                                                                    Value="{Binding PressedImage, RelativeSource={RelativeSource TemplatedParent}}" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Image x:Name="ButtonBrush" Source="{TemplateBinding NormalImage}" Stretch="Fill" />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style> 
</ResourceDictionary>
<VisualState x:Name="Normal">
   <Storyboard>
     <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="NormalButton"/>
   </Storyboard>
</VisualState>