【发布时间】:2018-04-06 07:54:07
【问题描述】:
我有一个带有ComboBox 的 wpf 项目。里面的项目是动态填写的。所以它绑定到一个包含Label 和命令的模型。
如果用户在下拉列表/ComboBox 中选择一个项目,则应执行命令。我用包含TextBlock 和Hyperlink 命令的DataTemplate 进行了尝试。但是该命令只会在选择 Label (Hyperlink) 时执行,而不是在我单击整个项目时执行。
<ComboBox ItemsSource="{Binding Path=States}" SelectedItem="{Binding CurrentState}" >
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock>
<Hyperlink Command="{Binding Command}" TextDecorations="None" Foreground="Black">
<TextBlock Text="{Binding Path=Label}"/>
</Hyperlink>
</TextBlock>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
所以现在的问题是,如何将我的命令绑定到 ComboBoxItem?
【问题讨论】:
标签: wpf xaml combobox binding command