1

I want to validate a ListBox: the user must select at least 2 items. The SelectedItems property doesn't support binding. So what now?

I miss the good old days when WinForms and ASP.NET controls had validation events, buttons had the CausesValidation property, etc...

fejesjoco
  • 11,763
  • 3
  • 35
  • 65

1 Answers1

1

You could probably handle the selected items changed event using a Trigger or Behaviour and then use the INotifyDataErrorInfo to create a validation errors for that control.

http://www.silverlightshow.net/items/Behaviors-and-Triggers-in-Silverlight-3.aspx

http://attachedwpf.com/blog/2010/03/24/silverlight-4-inotifydataerrorinfo/

BenCr
  • 5,991
  • 5
  • 44
  • 68
  • I thought about that, but how will the control be notified of the error? Since I can't bind to it, it won't ask me if there are any errors. – fejesjoco Apr 15 '11 at 09:14
  • This seems to show a good way to bind selected items. http://stackoverflow.com/questions/1297643/sync-selecteditems-in-a-muliselect-listbox-with-a-collection-in-viewmodel/1299544#1299544 – BenCr Apr 15 '11 at 09:20