位于网格行中。
问题是我没有得到任何组合框的鼠标选择没有被解雇。但是从关键板开始,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>
答案 0 :(得分:0)
如果你关注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接口,因此只要所选项目发生更改,属性更改事件就会触发(与触发源无关)