2015-12-11 112 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接口的屬性改變的事件將觸發每當選擇的項目改變(獨立於觸發源)