I need a button-style menu, i.e. horizontally arranged group of always visible buttons.
Like radiobuttons they should have a selected property, i.e. the click-command should fire only when the selected status changes to true, not on every click as with a normal button.
相关问题
- VNC control for WPF application
- WPF Binding from System.Windows.SystemParameters.P
- XAML: Applying styles to nested controls
- How can I add a horizontal line (“goal line”) for
- How to properly change a resource dictionary
Dude, this is WPF, you can use any control that fits some or any of your requirements and then simply provide a new
ControlTemplate
for it. Incidentally, there is noSelected
orIsSelected
property on aRadioButton
... perhaps you were referring to theIsChecked
property? This property is inherited from theToggleButton
, so that may be more appropriate.As the
ToggleButton
is already aButton
, you could even get away without providing a newControlTemplate
for it.As for your requirement regarding the
Click
event, I don't think that you will find that functionality on any of the WPF controls, but it could be manually implemented:It turned out that a ListBox with a horizontal layout in a WrapPanel suits my scenario perfectly. I posted the solution in another question.
RadioButton
also like other Buttons fireClick
event on every click. Also there is no Selected property on theRadioButton
.But if you want your
MenuItems
to be likeButton
, then you can useToggleButton
here.ToggleButton
hasIsChecked
Property which tracks the checked state of button andChecked
event which is fired whenToggleButton
is Checked.Also, if you want to automatically check/uncheck your ToggleButtons on click of other ToggleButton then you can use
RadioButton
asDataTemplate
of yourMenuItem
and override itsTemplate
like below: