WPF MVVM 中的 Button.IsSelected 属性类型?
我的 WPF 应用程序中有几个按钮作为菜单。
这种情况类似于网站中的菜单。
当我单击其中一个按钮时,我希望该按钮样式与其他按钮不同,而当我选择另一个按钮时,前一个按钮应该是正常的,并且选定的样式应该应用于该选定的按钮。
您能告诉我如何通过 ControlTemplate 实现此目的,还是必须维护 IsSelected 属性来让我们知道选择了哪个按钮?
谢谢,
VJ
I have few buttons as Menu in my WPF App.
This scenario is something like menu in a website.
When I click one of the button, I want that button style to be different from others, and when I select another, the previous one should be normal and a selectedstyle should apply on this selected button.
Can you tell me how can I achieve this through ControlTemplate or do I have to maintain a IsSelected property that let us know which button is selected?
Thanks,
VJ
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以尝试使用 RadionButton。下面的示例将为 RadioButton 创建一个平面按钮外观。
对于带有图像的 RadioButton,只需查看 Matt 的博客
http://madprops.org/博客/wpf-killed-the-radiobutton-star/
You can try with the RadionButton. The below sample will create a Flat button look for the RadioButton.
for RadioButton with Image just have look at Matt's blog
http://madprops.org/blog/wpf-killed-the-radiobutton-star/
您应该使用内置的视觉状态处理并在 XAML 中创建状态/样式。
在您的具体案例中,您似乎需要的是一组RadioButtons,这样您就不必编写任何代码来处理状态之间的切换。
You should use the built in visual state handling and create the states / styles in XAML.
In your concrete case it seems that what you're after is a group of RadioButtons, so that you don't have to write any code to deal with switching between states.
为此,您最好使用自定义单选按钮列表。查看以下帖子。
不允许在列表框中取消选择/取消选择
您可以轻松自定义选定和取消选定的样式以满足您的要求
You better Use a Custom RadioButton List for this purpose.Check out the below post.
Do not allow unselect/deselect in ListBox
You can easily customize the selected and deselected styles to match your requirement