【发布时间】:2010-01-06 11:33:04
【问题描述】:
我想将命令绑定到组合框项,就像将典型命令(应用程序或自定义)绑定到按钮一样。我似乎找不到一个例子。
编辑:
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>
【问题讨论】:
-
您希望命令何时执行?是希望每次选中项发生变化时都执行命令,还是希望能够在不触发命令的情况下更改选中项?
-
它是基于 ComboBox 的模板化拆分按钮的一部分。我希望它在单击时执行以及更改拆分上的图像,以便我下次只需单击按钮即可重新发出命令。类似于为电子表格中的单元格选择背景颜色。
标签: wpf xaml binding combobox command