【发布时间】:2019-11-22 03:52:31
【问题描述】:
我有一个 ComboBox,我定义了它的 ItemTemplate。我希望在单击组合框项或选中/取消选中它之前的复选框时触发组合框 selectionChanged 命令。这里是 xmal:
<ComboBox x:Name="DeptComboBox"
Grid.Row="2" Grid.Column="3"
IsReadOnly="True"
StaysOpenOnEdit="True"
ItemsSource="{Binding DeptDtoes}"
Text="{Binding SelectedDeptNames}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding DeptSelectedCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<ComboBox.ItemTemplate>
<DataTemplate>
<CheckBox Content="{Binding Name}" IsChecked="{Binding IsSelected}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
还有 ViewModel:
public class AddDoctorViewModel:ViewModelBase, ISingletonDependency
{
private readonly IBasicAppService _basicAppService;
public ObservableCollection<DeptDto> DeptDtoes { get; }
private string _selectedDeptNames;
public string SelectedDeptNames
{
get { return _selectedDeptNames; }
set
{
_selectedDeptNames = value;
RaisePropertyChanged(nameof(SelectedDeptNames));
}
}
private int _selectedIndex;
public int SelectedIndex
{
get { return _selectedIndex; }
set
{
_selectedIndex = value;
RaisePropertyChanged(nameof(SelectedIndex));
}
}
public RelayCommand DeptSelectedCommand { get; set; }
public AddDoctorViewModel(IBasicAppService basicAppService)
{
_basicAppService = basicAppService;
DeptDtoes = new ObservableCollection<DeptDto>(_basicAppService?.DeptDtoes);
DeptSelectedCommand = new RelayCommand(DeptSelected);
}
private void DeptSelected()
{
}
}
但是组合框 selectionChanged 命令没有触发。谁能帮助我?
【问题讨论】:
-
(stackoverflow.com/questions/8666256/…) 这可能会对您有所帮助.. 我想您在 xaml 中错过了
SelectedItem="{Binding someitems}" -
不,它不起作用,我认为可能是
一些如何停止 SelectionChanged cammand 触发。如果我不设置组合框的 部分,该命令将起作用。