[英]WPF ComboBox mouse selection event is not getting fired
它位於網格行內。
問題是我沒有在任何comboboxitem上都沒有觸發鼠標選擇。 但是從鍵盤來看,keydown事件正在被觸發並且運行得很好。
所以任何想法,為什么下面的XAML ComboBox不會觸發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>
如果您關注的是MVVM,則有一種簡單的方法可以做到這一點:
<ComboBox Name="StatusCombo" ItemsSource="{Binding Path=StatusComboCollection,UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
SelectedItem="{Binding MySelectedItem,UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}>
在ViewModel中
private string _mySelectedItem;
public string MySelectedItem
{
get { return _mySelectedItem; }
set {
//Do the operations here no need for an extra method
_mySelectedItem = value;
}
}
注意:由於您已經實現了InotifyPropertyChanged接口,因此只要更改了所選項目,屬性更改事件就會觸發(與觸發源無關)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.