gpt4 book ai didi

c# - 如何实现一个双态按钮

转载 作者:太空宇宙 更新时间:2023-11-03 21:06:59 24 4
gpt4 key购买 nike

我有一个简单的按钮,我希望它具有“粘性”按钮的行为,例如它在视觉上有两种状态(很像开关)。换句话说,我希望它即使在我释放鼠标按钮后也能保持其按下的样式,但它必须是可点击的。

有没有办法在 WPF 中轻松做到这一点?我正在使用 Fluent,但如果需要我可以更改它。

<Fluent:Button Header="myButton" Command="{Binding ToggleCommand}" SizeDefinition="Small">
<Fluent:Button.Icon>
<Grid Width="16" Height="16">
<Image Source="../Images/16x16/icon.png"/>
</Grid>
</Fluent:Button.Icon>
</Fluent:Button>

像这样:

1- not-pressed2- pressed

附言:

我正在使用 MVVM,在 Command 中,我正在检查和更改 bool 标志以了解按钮当前的状态。如果有任何帮助,我可以将它绑定(bind)到按钮属性。

最佳答案

原来有一个组件 ToggleButton 完全符合我的要求。真傻,我一开始不知道它的存在。

关于c# - 如何实现一个双态按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40677202/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com