Setting ComboBox SelectedItem in MVVM

3 posts, 0 answers
  1. Christopher
    Christopher avatar
    4 posts
    Member since:
    Dec 2010

    Posted 17 Feb 2011 Link to this post

    I have a child window that contains a number of RadComboBoxes.  This child window has it's data context set to a ViewModel that has a number of properties on it.  Some of the properties are ObservableCollection<T> that are used as item sources for the RadComboBoxes.  All of these RadComboBoxes have their selected item property bound to properties on the ViewModel.  In our ViewModel's constructor, I'm injecting an instance of the class that our RadComboBoxes have their selected item properties bound to.  My assumption is that when the child window loads, since we're injecting an existing instance, the RadComboBoxes should have an initial value equal to whatever their corresponding properties are set to.  However this is not the behavior we're seeing.  Instead, all of the RadComboBoxes have blank initial values.

    Any insight you could provide on resolving this would be appreciated.

    Thanks!

    Chris
  2. George
    Admin
    George avatar
    1332 posts

    Posted 22 Feb 2011 Link to this post

    Hi Christopher,

     
    Please, refer to the following forum thread - http://www.telerik.com/help/silverlight/radcombobox-features-selection.html

    I hope this helps.

    Greetings,
    George
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  3. DevCraft banner
  4. Christopher
    Christopher avatar
    4 posts
    Member since:
    Dec 2010

    Posted 22 Feb 2011 Link to this post

    Thanks, I found the solution on my own however.  It appears that it was an issue of timing.  I was trying to set the selected index in my view's ctor.  However the binding had not yet been established at this point, so I instead needed to set the selected index for each combobox in it's Loaded event.  Not a pretty solution, but it works.

    Chris
Back to Top