1
現在我只想在鼠標懸停時將按鈕的背景更改爲#f5f5f5。
WPF具有觸發功能,可以輕鬆完成。
雖然我聽說UWP沒有觸發任何更多,但與其他函數來代替,像這樣的問題:
Trigger element (XAML) is not supported in a UWP project如何在鼠標懸停在UWP時更改按鈕的背景?
我DataTriggerBehavior做了它作爲教程:
<ControlTemplate TargetType="Button" x:Key="ButtonControlTemplate">
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" VerticalAlignment="{TemplateBinding VerticalAlignment}" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" Name="ButtonBorder" Background="{TemplateBinding Background}">
<ContentPresenter FontSize="{TemplateBinding FontSize}" FontFamily="{TemplateBinding FontFamily}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Foreground="{TemplateBinding Foreground}"></ContentPresenter>
</Border>
<Interactivity:Interaction.Behaviors>
<Core:DataTriggerBehavior Binding="{Binding PointerMovedEvent, ElementName=ButtonBorder}" Value="true">
<Core:ChangePropertyAction TargetObject="{Binding ElementName=ButtonBorder}" PropertyName="Background" Value="#f5f5f5" />
</Core:DataTriggerBehavior>
</Interactivity:Interaction.Behaviors>
</ControlTemplate>
程序可以成功工作,但不能更改背景。
哦,我的上帝。
我也嘗試過VisualState,但是我找不到教程,所以我不知道如何使用它。
更重要的是,我幾乎不知道爲什麼微軟不再使用觸發器。
你能幫我解決我的問題嗎?
非常感謝!
感謝您再次幫助我。我想我必須馬上學習更多關於VisualState的知識。 –