XAML/WPF:如何将命令绑定到组合框项
我想将命令绑定到组合框项目,就像将典型命令(应用程序或自定义)绑定到按钮一样。我似乎找不到例子。
编辑:
ComboBoxItem 作为还包含按钮的 ContentControl 的一部分存在。该按钮有一个运行良好的关联命令。如何以类似的方式将命令绑定到 ComboBoxItem?
<!-- Line -->
<Button x:Name="Line"
Style="{DynamicResource Button_Title}"
Grid.Row="1"
Grid.RowSpan="3"
Grid.Column="0"
Content="Line"
Command="{x:Static local:Ribbon_AC.Custom_RoutedUICommand}"
CommandParameter="Line"
Tag="{DynamicResource Line_32}"/>
<!-- Arc -->
<ContentControl x:Name="ArcSplit"
Template="{DynamicResource Control_SplitSmall}"
Tag="{DynamicResource Arc_20}"
Grid.Row="1"
Grid.Column="1">
<ComboBox Name="ComboBox_Arc"
Style="{DynamicResource ComboBox_Small}"
Width="{DynamicResource Width_DropDown}">
<!-- Arc_0 -->
<ComboBoxItem x:Name="Arc_0"
Style="{DynamicResource ComboBoxItem_Large}"
Tag="{DynamicResource Arc0_32}"
Content="Arc 0">
</ComboBoxItem>
I want to bind a command to a comboboxitem much like a typical command (either application or custom) is bound to a button. I can't seem to find an example.
EDIT:
The ComboBoxItem exists as part of a ContentControl that also contains a button. The button has an associated command that works well. How can I bind a command, in a similar way, to the ComboBoxItem?
<!-- Line -->
<Button x:Name="Line"
Style="{DynamicResource Button_Title}"
Grid.Row="1"
Grid.RowSpan="3"
Grid.Column="0"
Content="Line"
Command="{x:Static local:Ribbon_AC.Custom_RoutedUICommand}"
CommandParameter="Line"
Tag="{DynamicResource Line_32}"/>
<!-- Arc -->
<ContentControl x:Name="ArcSplit"
Template="{DynamicResource Control_SplitSmall}"
Tag="{DynamicResource Arc_20}"
Grid.Row="1"
Grid.Column="1">
<ComboBox Name="ComboBox_Arc"
Style="{DynamicResource ComboBox_Small}"
Width="{DynamicResource Width_DropDown}">
<!-- Arc_0 -->
<ComboBoxItem x:Name="Arc_0"
Style="{DynamicResource ComboBoxItem_Large}"
Tag="{DynamicResource Arc0_32}"
Content="Arc 0">
</ComboBoxItem>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
作为选项之一,您可以考虑将按钮放入组合框的 ItemTemplate 中,并更改按钮的模板以使其看起来“根本不像按钮”。
但那很脏。也许您可以使用菜单而不是组合框?
As one of the options you can consider putting a Button into the ComboBox's ItemTemplate and change the Button's template to make it look "not like a button at all".
But that is dirty. Maybe you can use Menu instead of ComboBox?