ComboBoxItem Question [modified]
-
Greetings, What is the best way to get a reference to a combobox item? I want to make certain options within the combobox, while visible, unavailable to the user in a combobox based on selections made elsewhere. So my plan is to get a reference to it, change the background color, and disable it. Can I do the following: ComboxBoxItem option = ComboBoxOptions.SelectedItem as ComboBoxItem; option.IsEnabled = false; option.Background = Colors.Gray; Also, if I have set the datacontext for the ListBox, can I listen to its "SourceUpdated" event? Thanks for any help you can provide.
modified on Tuesday, December 29, 2009 7:38 PM
-
Greetings, What is the best way to get a reference to a combobox item? I want to make certain options within the combobox, while visible, unavailable to the user in a combobox based on selections made elsewhere. So my plan is to get a reference to it, change the background color, and disable it. Can I do the following: ComboxBoxItem option = ComboBoxOptions.SelectedItem as ComboBoxItem; option.IsEnabled = false; option.Background = Colors.Gray; Also, if I have set the datacontext for the ListBox, can I listen to its "SourceUpdated" event? Thanks for any help you can provide.
modified on Tuesday, December 29, 2009 7:38 PM
BlitzPackage wrote:
disable
Try to bind the combo box's disabled property.
BlitzPackage wrote:
datacontext
Use INotifyPropertyChanged along with the datacontext's source.
There are only 10 types of people in this world — those who understand binary, and those who don't.
-
BlitzPackage wrote:
disable
Try to bind the combo box's disabled property.
BlitzPackage wrote:
datacontext
Use INotifyPropertyChanged along with the datacontext's source.
There are only 10 types of people in this world — those who understand binary, and those who don't.
Thank you for your reply. While I would try to bind to the ComboBox's disabled property, I need the individual ComboBox items to be enabled or disabled based on user input in another control. Thanks for the second suggestion, I will pursue it or a variant thereof.
-
Thank you for your reply. While I would try to bind to the ComboBox's disabled property, I need the individual ComboBox items to be enabled or disabled based on user input in another control. Thanks for the second suggestion, I will pursue it or a variant thereof.
BlitzPackage wrote:
I need the individual ComboBox items to be enabled or disabled based on user input in another control
You can bind to other controls. And if the logic is complex (e.g., enabled only if they enter an even number), you can use a class which implements IValueConverter or IMultiValueConverter to produce a bool from the values input by the user in one or more other controls. Also, if you bind the other control to a view model, you can then bind to that view model in the original control (i.e., two controls can bind to the same view model).