I couldn’t find a proper event which fires when my ComboBox.Items count changed. Is there any way to do so?
I couldn’t find a proper event which fires when my ComboBox.Items count changed. Is
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Bind ComboBox ItemsSource to ObservableCollection, then you can catch the event CollectionChanged of ObservableCollection
EDIT:
In wpf it is recommended to use binding instead of accessing UI element properties directly, of course better to use MVVM, but you can live without it too
in your Windows or UserControls C# code you can keep property like this
Initialize it in constructor
than name your UserControl in xaml like this
write your ComboBox like this
now instead of adding and removing items to combobox element, add tham to MyCollection, they will appear in combobox
Hope this helps