Appbar按钮的颜色直到onclick函数返回才持续
本文关键字:返回 函数 onclick 按钮 颜色 Appbar | 更新日期: 2023-09-27 18:01:51
在点击联系人图标时,它的背景颜色变为蓝色,但立即返回到原来的颜色。我想保持背景颜色为蓝色,直到OnClick函数返回。我想知道有什么办法去吗?
<Page.BottomAppBar>
<CommandBar>
<CommandBar.PrimaryCommands>
<AppBarButton x:Name="ContactBtn" x:Uid="Contact_id" Icon="Contact" Label="View Contacts" Click="OnClick" />
</CommandBar.PrimaryCommands>
</CommandBar>
</Page.BottomAppBar>
按钮的样式取决于它的VisualState。我认为最简单的方法是使用AppBarToggleButton
并在执行期间将其IsChecked
设置为true
。
Click将其自动设置为true,因此您只需要将其重置为false
。
但这仍然不像听起来那么容易。因为只有当你在点击事件中做一些异步的事情或者你打开Popup
或类似的事情时,这才会有效果。
如果你只做同步的东西,按钮UI将不会更新。所以我认为这已经是async了
在OnClick方法开始时设置AppBarButton的IsPressed属性为true,在结束时设置为false;
编辑
<interactivity:Interaction.Behaviors>
<core:DataTriggerBehavior Binding="{Binding Path=IsPressed, RelativeSource={RelativeSource Self}" Value="True">
<core:ChangePropertyAction PropertyName="Background" Value="Blue"/>
</core:DataTriggerBehavior>
<core:DataTriggerBehavior Binding="{Binding Path=IsPressed, RelativeSource={RelativeSource Self}" Value="False">
<core:ChangePropertyAction PropertyName="Background" Value="Black"/>
</core:DataTriggerBehavior>
</interactivity:Interaction.Behaviors>
当IsPressed改变时,你可以设置你想要的背景