2015-12-11 108 views
0

位于网格行内。WPF组合框鼠标选择事件未被触发

问题是我没有得到鼠标选择的任何comboboxitem没有被解雇。但是从关键董事会来看,keydown事件正在被解雇并且工作得很好。

所以,任何想法,为什么下面的XAML组合框不会触发mousedown或selectionItem事件。

<ComboBox Name="StatusCombo" VerticalAlignment="Center" MouseDown="StatusCombo_MouseDown" 
         Margin="10,0,0,0" Width="Auto" MinWidth="75" 
         FontFamily="Arial" FontSize ="10px" FontWeight ="Normal" 
         SelectedIndex="{Binding IndexForSelectedStatus}" 
         SelectedItem="{Binding SelectedItemStatus, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" 
         ItemsSource="{Binding Path=StatusComboCollection,UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" 
         Style="{StaticResource UIRefreshButtonComboBoxStyle}" 
         AutomationProperties.Name="{Binding ElementName=labelStatus,Path=Content}"> 

       </ComboBox> 
+0

您是否遵循经典模式/ MVVM? –

+0

尝试预览鼠标下降https://social.msdn.microsoft.com/Forums/en-US/61807025-d4c4-41e0-b648-b11183065009/mousedown-event-not-working-wpf?forum=wpf –

+0

也许GridRow是将鼠标放下事件尝试PreviewMOuseDown @CaseyPrice如何说出 – Jamaxack

回答

0

如果你正在跟踪MVVM有做同样的一个简单的方法:

在视图模型
<ComboBox Name="StatusCombo" ItemsSource="{Binding Path=StatusComboCollection,UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" 
SelectedItem="{Binding MySelectedItem,UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}> 

private string _mySelectedItem; 
public string MySelectedItem 
{ 
    get { return _mySelectedItem; } 
    set { 
     //Do the operations here no need for an extra method 
     _mySelectedItem = value; 
     } 
} 

注:既然你已经实现了INotifyPropertyChanged接口的属性改变的事件将触发每当选择的项目改变(独立于触发源)