MULTIPLE SELECTIONS IN RADLISTBOX USING MVVM

4 posts, 0 answers
  1. Shruti
    Shruti avatar
    10 posts
    Member since:
    Jul 2013

    Posted 13 Aug 2013 Link to this post

    Hi,
    I have a query.I am developing WPF app and using MVVM Architecture.
     I have a RadListbox which gives the option of selecting multiple items.I want to access the selected items in my Viewmodel. How do i do it??

    Thanks in advance

    Shruti
  2. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 14 Aug 2013 Link to this post

    Hi Shruti,

    I would suggest that you check the following blog post which explains how to achieve the needed approach:
    http://blogs.telerik.com/xamlteam/posts/13-01-14/extending-the-functionality-of-radcontrols-with-attached-properties

    Regards,
    Yana
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. David
    David avatar
    6 posts
    Member since:
    Jun 2013

    Posted 13 Feb 2014 in reply to Yana Link to this post

    Unfortunately the code in the blog post is a bit buggy.
    The first selection is off.

    Also, it's not generic.
  5. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 18 Feb 2014 Link to this post

    Hi David,

    The issue with the initial selection is already logged in our Feedback Portal, you can track its progress at the following link:
    http://feedback.telerik.com/Project/143/Feedback/Details/118799-using-an-attached-property-to-populate-the-selecteditems-of-the-control-initially

    As a workaround you could simply set the SelectedItems in the Loaded event of the control rather than in the ViewModel:

    private void ListBox_Loaded(object sender, RoutedEventArgs e)
    {
         var items = this.ListBox.ItemsSource as ObservableCollection<Country>;
         this.MyViewModel.SelectedCountries = new System.Collections.ObjectModel.ObservableCollection<Country>()
         {
        items[4],
        items[5],
        items[6],
        items[7]
         };
    }

    I hope this helps.

    Regards,
    Yana
    Telerik
Back to Top