Dealing with Selectionchanged and currentlyselected item in viewmodel?

99 Views Asked by At

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

1

There are 1 best solutions below

0
On

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);
        }
    }
}