views:

14

answers:

1

Hello,

I have a form and a button should be enabled only if the listbox is not empty. How can I do binding for this case?

Note: I would like to avoid creating custom converter.

Thanks!

+2  A: 

Multiple options,

  1. if you're using a MVVM pattern - your ViewModel could expose a ShouldShowDetails property, which checks the itemCount (visualized by the listbox) and returns a boolean. Bind the enabled properties of the dependent controls to this property. (Recommended)
  2. Write a Trigger on the dependent controls - which resets the enabled property if the value of the listbox's itemCount property is 0.
  3. Write a itemCount to boolean converter and bind to the ListBox's ItemCount property directly
Gishu
Thanks! The first option is easier for me. I was just curious if it could be done in XAML. Just because of code elegance.
MartyIX