0

Could anyone please provide an example of how i can handle storing the currently selected item, within a longlistselector( or any list control ) within my viewmodel. I seem to fail to understand how to implement the logic within the viewmodel, keeping it out of the event handler within the pages codebehind! thanks

user2309367
  • 317
  • 2
  • 8

1 Answers1

0

See this article, if you want to call events with binding http://www.wiredprairie.us/blog/index.php/archives/1701

If you want to store the SelectedItem in your ViewModel, your xaml should look something like this:

<ComboBox SelectedItem="{Binding MySelectedItem, Mode=TwoWay}"/>

and your ViewModel should look like this:

public class ContactModel : ViewModelBase

public ContactModel()
{
    MySelectedItem = "";
}

   private string _myselecteditem
   public string MySelectedItem
    {
        get { return _myselecteditem; }
        set
        {
            _myselecteditem = value;
            RaisePropertyChanged(() => MySelectedItem);
        }
    }
}
Rudi
  • 926
  • 2
  • 19
  • 38