Xaml 使用交互性更改UWP中输入的按钮指针事件

Xaml 使用交互性更改UWP中输入的按钮指针事件,xaml,uwp,Xaml,Uwp,当指针进入按钮时,我想更改背景色。因此我添加了参考交互和核心。我的代码是: <Button Name="clickbutton" Height="60" Width="150" VerticalAlignment="Center" Content="ClickButton" Margin="150,20,0,0" Foreground="Black" Background="Bisque" ClickMode="Pres <Interactivity:

指针进入按钮时,我想更改背景色。因此我添加了参考交互和核心。我的代码是:

<Button Name="clickbutton" Height="60" Width="150"  VerticalAlignment="Center" Content="ClickButton" Margin="150,20,0,0" Foreground="Black" Background="Bisque" ClickMode="Pres
               <Interactivity:Interaction.Behaviors>
                    <Core:DataTriggerBehavior  Binding="{Binding PointerEnteredEvent ,ElementName=clickbutton}" Value="True">
                        <Core:ChangePropertyAction PropertyName="Background" Value="Green"/>
                    </Core:DataTriggerBehavior>
                </Interactivity:Interaction.Behaviors>
</Button>

您使用的是
DataTriggerBehavior
,这在这里是不合适的。改为使用
EventTriggerBehavior
,它在触发事件时触发(将事件名称放入
EventName
属性中,不带任何后缀)


如果希望在鼠标输入时按钮的背景立即变为绿色,请将
EventName
更改为
PointerMoved
。 但我建议更改按钮的默认模板以实现这一点

<Core:EventTriggerBehavior EventName="PointerEntered">
   <Core:ChangePropertyAction PropertyName="Background" Value="Green"/>
</Core:DataTriggerBehavior>