0
我有一個組合框。這裏是MVVM風格使用命令其引發LostFocus:
<ComboBox .............>
<i:Interaction.Triggers>
<i:EventTrigger EventName="LostFocus">
<i:InvokeCommandAction Command="{Binding DataContext.OrderIdLostFocusCommand, UpdateSourceTrigger=PropertyChanged,
RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox>
並在視圖模型:
//Constructor
public DispatchViewModel(IEventAggregator _eventAggregator)
{
eventAggregator = _eventAggregator;
//Some Code
OrderIdLostFocusCommand = new RelayCommand(Execute_OrderId_LostFocus);
}
public RelayCommand OrderIdLostFocusCommand { get; set; }
private void Execute_OrderId_LostFocus(object obj)
{
//Some Calculations
eventAggregator.GetEvent<MoveFocusToDatePickerEvent>().Publish(true);
}
在代碼背後:
//Constructor
public DispatchView(DispatchViewModel _viewModel, IEventAggregator _eventAggregator)
{
InitializeComponent();
this.DataContext = _viewModel;
_eventAggregator.GetEvent<MoveFocusToDatePickerEvent>().Subscribe(MoveFocusToDateOfDispatch);
}
private void MoveFocusToDateOfDispatch(bool obj)
{
this.Dispatcher.BeginInvoke((Action)delegate { dpInvoice.Focus(); }, DispatcherPriority.Render);
}
問題:
當Combobox被關注時,如果我嘗試打開它的DropDown,那麼它的lostFocus事件觸發,所以焦點移動到DataPicker。
我想要什麼:
相反,我想火LostFocus事件只有當IsKeyboardFocusWithin ComboBox控件的屬性爲false。
但是我怎麼能在DataTrigger中使用觸發器? – Vishal
DataTriggers無所不能。 –
謝謝H.按預期工作。 – Vishal