ComboBox ItemsSource changed => SelectedItem is ruined

前端 未结 8 923
忘掉有多难
忘掉有多难 2020-12-05 10:36

Ok, this has been bugging me for a while now. And I wonder how others handle the following case:



        
8条回答
  •  抹茶落季
    2020-12-05 11:05

    I just implemented a very simple override and it seems to be working visually, however this cuts off bunch of internal logic, so I'm not sure it's safe solution:

    public class MyComboBox : ComboBox 
    {
        protected override void OnItemsChanged(NotifyCollectionChangedEventArgs e)
        {
            return;
        }
    }
    

    So if you use this control then changing Items/ItemsSource won't affect SelectedValue and Text - they will remains untouched.

    Please let me know if you find problems it causes.

提交回复
热议问题