[英]How to fire the Combobox Selection Changed event if there's only 1 entry in the drop down
我在 WPF 中有一個 Combobox,我正在使用 MVVM 模式。 當 combobox 項目選擇發生更改時,它會觸發一個執行一些操作的事件。 但是,如果下拉列表中只有 1 個條目,它會第一次觸發該事件我 select 它。 之后,如果我再次 select 它,它就不會調用 SelectionChanged 事件。 有沒有辦法做到這一點?
這是我的代碼:
<ComboBox x:Name="DataComboBox" MinWidth="125" Text="" Margin="5,3" VerticalAlignment="Center" Grid.Row="8" Grid.Column="1" Style="{StaticResource ComboBoxFlatStyle}"
IsEditable="True" IsReadOnly="True" ItemsSource="{Binding ComboBoxList}" DisplayMemberPath="Scan_File_Name" SelectedItem="{Binding SelectedItems}"></ComboBox>
private string selectedItem;
public string SelectedItem
{
get { return selectedItem; }
set
{
if (value != selectedItem)
{
selectedItem= value;
OnPropertyChanged("SelectedItem");
SelectedItemsChanged();
}
}
}
private void SelectedImagesChanged()
{
//Do some work
}
在 WPF 中,選擇更改事件僅在值更改時發生。 下拉組合框並單擊同一條目不會更改所選條目。 因此不會觸發任何事件。
還有其他方法可以做你想做的事,但不太可能需要它們。
可以捕獲單擊 combobox 中的條目的單擊事件,並像選擇更改一樣處理它
如果需要刷新表單上的數據,可以添加一個 REFRESH DATA 按鈕。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.