我想以在组合框旁边显示两个按钮的方式扩展 WPF 组合框。我无法使用 UserControl,因为我需要在纯 xaml 中指定组合框的项目,如下所示:
<CustomComboBox>
<CustomComboBoxItem />
<CustomComboBoxItem />
</CustomComboBox>
我非常害怕采用组合框的模板并扩展它,因为对于组合框来说它非常大且复杂。我正在寻找一种简单的解决方案来创建那种类似 ComboBox 的 ItemsControl
,只附加两个按钮。欢迎提出建议!
I want to extend the WPF Combobox in a way that two buttons are displayed next to the combobox. I cannot use a UserControl, because I need to specify the items of the combobox in pure xaml like this:
<CustomComboBox>
<CustomComboBoxItem />
<CustomComboBoxItem />
</CustomComboBox>
I'm quite scared to take the template of the combobox and extend it, because for comboboxes it is very large and complex. I'm looking for an easy and simple solution to create that kind of ComboBox-like ItemsControl
with just two buttons attached to it. Suggestions welcome!
发布评论
评论(1)
编辑:使用
UserControl
的具体示例:Xaml:
代码:
用法:
外观:
UserControl 应该可以,您仍然可以在 Xaml 标记中指定项目,例如,如果我有一个时间用户控件,我可以这样做:
这样您就可以在 XAML 中设置时间:
您应该能够调整它来设置 ComboBox 的项目。
Edit: Conrete example using a
UserControl
:Xaml:
Code:
Usage:
Appearance:
A UserControl should do fine, you can still specify the items in Xaml markup, e.g. if i have a time user control i can do this:
That way you can set the hours in XAML:
You should be able to adapt this to set the items of your ComboBox.