Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

Databinding trigger in DataTemplate RSS

0 replies

Last post Jun 13, 2009 08:30 AM by argyreos

(0)
  • argyreos

    argyreos

    Member

    39 Points

    78 Posts

    Databinding trigger in DataTemplate

    Jun 13, 2009 08:30 AM | LINK

    Hi group, I have a MVVM-like SL application where a view binds to a view model object using a data template, applied to the items of a listbox. Some of the properties of this object are string properties bound to editable textboxes. The VM of course implements INotifyPropertyChanged for these properties, and the binding is a two-way binding. So users can select any of the listbox items and start typing in the textboxes bound to these properties. This basically works, but I have issues with focus management: the binding is triggered when focus is lost, as this is the only way of doing it in SL 2, so that if users just move away from the listbox to click e.g. a save button elsewhere the property being edited is not updated and thus not saved. I've tried some workarounds, like handling the LostFocus event in the container itself of the listbox (the view itself, a user control), as this event bubbles up: there I change the selectedindex of the listbox item and then restore the originally selected item index, but nothing changes, and users still have to manually select another listbox item and click in any of its textboxes so that the other item VM object can be updated by binding. There would be no problem if I could use an on-property-changed trigger in binding, but this is not possible at least in SL 2. Could anyone suggest a solution for such a scenario?

    Thanks!