【发布时间】:2016-09-27 06:48:03
【问题描述】:
我的 WPF 窗口中有一个 SplitButton,它是从 Xceed 的扩展 WPF 工具包中借来的。它的下拉内容由一些RadioButtons 组成。比如:
<Window x:Class="WpfTest.Test3"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:tk="clr-namespace:Xceed.Wpf.Toolkit;assembly=Xceed.Wpf.Toolkit"
Title="Test3" Height="300" Width="300">
<Grid Height="25" Width="150">
<tk:SplitButton Content="Default Command">
<tk:SplitButton.DropDownContent>
<StackPanel>
<RadioButton Content="Default Command" GroupName="variations" Margin="5" IsChecked="True"/>
<RadioButton Content="Alternate Command 1" GroupName="variations" Margin="5"/>
<RadioButton Content="Alternate Command 2" GroupName="variations" Margin="5"/>
</StackPanel>
</tk:SplitButton.DropDownContent>
</tk:SplitButton>
</Grid>
</Window>
它会生成这样的东西:
问题是,当我点击每个RadioButtons 时,下拉菜单并没有消失。我做了一些谷歌搜索并意识到我应该为每个RadioButton 处理Click 事件。但我不知道如何隐藏该事件处理程序中的下拉菜单。作为旁注,它似乎是MenuItemhas the property ofStaysOpenOnClick,但其他控件则没有。
虽然以编程方式执行此操作就足够了,但有没有 MVVM 方法呢?
【问题讨论】:
-
不完全是您问题的解决方案,但为什么您更喜欢单选按钮而不是下拉列表?
-
@Zure 什么是下拉列表?
SplitButton有一个DropDownContent属性,可以用MenuItems 或类似我尝试过的东西填充。我没明白你的意思 -
对不起,我的意思是一个组合框:dotnetperls.com/combobox-wpf
标签: c# wpf drop-down-menu split-button wpf-extended-toolkit