【发布时间】:2023-05-28 04:26:01
【问题描述】:
我正在尝试播放/暂停Button。
单击Play Button 时,将绑定到StartStopWatch 命令。
然后Play Button 将更改为Pause Button,该Pause Button 将绑定到PauseStopWatch 命令。
我的问题是。我不知道如何保持它的风格并可以互换地改变它们。目前我有两个不同的按钮,但我想将它们合并在一起并将它们合二为一。
我的按钮如下。我想在MouseClick 上拥有它,它也会改变!谢谢!
<Button x:Name="StartButton" Style="{DynamicResource StartTimerButton}"
Width="24" Height="24" Margin="5,0,5,0" ToolTip="Start Timer"
Command="{Binding StartStopWatch}" VerticalAlignment="Center"/>
<Button x:Name="StopButton" Style="{DynamicResource StopTimerButton}"
Width="20" Height="20" Margin="0,0,5,0" ToolTip="Stop Timer"
Command="{Binding StopStopWatch}" VerticalAlignment="Center"/>
有人有什么建议吗?
【问题讨论】:
-
请说明您想要达到的目标。您想动态切换按钮上的样式和工具提示(可以作为样式 BTW 的一部分)吗?
-
当按钮被点击时,它会改变。例子。你有一个播放按钮。当您单击播放按钮时,它会变为暂停按钮。当您单击暂停按钮时,它会变为播放按钮。但是当它在播放时,它会绑定到命令播放。当它暂停时,它绑定到命令暂停。另外,我正在尝试在按钮上保持相同的样式。我有一个红色和绿色的按钮。红色 = 停止,绿色 = 走。