ListPicker Selected items binding

6 posts, 0 answers
  1. Paul Wade
    Paul Wade avatar
    8 posts
    Member since:
    Oct 2008

    Posted 24 Jul 2013 Link to this post

    I tried the obvious approach of using selecteditems as a two way binding so my viewmodel would know what from the list the user picked. Ok I have no idea why this wouldn't be implemented but apparently its not.. So on to some attempted work arounds.

    First I thought if my items object contained an IsSelected or even inherited from a base class like ListPickerItem the control would pass through to my object when I made a selection. Doesn't seem to.

    Next I decided to try selectedValue as a two way binding back to a collection of the same objects. No luck here either. Here is the VM code.

    The goal would be this
    1.Display a list of values to choose from with multi-selection.
    2.through data binding return the selected list to my vm.


       <telerikInput:RadListPicker  SelectedValue="{Binding SelectedValues,Mode=TwoWay, UpdateSourceTrigger=Default}" SelectedValuePath="Value"    DisplayMemberPath="DisplayValue"  HorizontalAlignment="Center" Margin="0" VerticalAlignment="Top" Width="300" SelectionMode="Multiple" ItemsSource="{Binding PosibleTables,Mode=TwoWay}"/>
           


        private List<ListPickerObject<int>> _posibletables;
            public List<ListPickerObject<int>> PosibleTables
            {
                get
                {
                    if (_posibletables == null)
                    {
                        _posibletables = new List<ListPickerObject<int>>();
                        for (int i = 0; i <= 30; i++)
                        {
                            _posibletables.Add(new ListPickerObject<int>() { DisplayValue = i.ToString(), Value = i });
                        }
                    }
                    return _posibletables;
                }
                set
                {
                    _posibletables = value;
                    RaisePropertyChanged(() => PosibleTables);
                }
            }

            public List<ListPickerObject<int>> SelectedValues
            {
                get
                {
                    return _selectedValues;
                }
                set
                {
                    _selectedValues = value; RaisePropertyChanged(() => SelectedValues);
                }
            }


       public class ListPickerObject<T> : GalaSoft.MvvmLight.ViewModelBase
        {
            private bool _isSelected;
            public string DisplayValue { get; set; }
            public T Value { get; set; }

            public bool IsSelected
            {
                get { return _isSelected; }
                set
                {
                    _isSelected = value;
                    RaisePropertyChanged(() => IsSelected);
                }
            }
        }


  2. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1512 posts

    Posted 29 Jul 2013 Link to this post

    Hello Paul,

    Indeed binding RadListPicker's SelectedItems is not supported yet. I've attached one possible workaround to your scenario. Please have a look at and let me know how it works for you. 

    Regards,
    Kiril Stanoev
    Telerik
    Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
  3. DevCraft banner
  4. Paul Wade
    Paul Wade avatar
    8 posts
    Member since:
    Oct 2008

    Posted 30 Jul 2013 Link to this post

    I was thinking about that as an option, not ideal obviously but yes it will work.

    Any idea on when selected items would be implemented as a dp?

  5. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1512 posts

    Posted 31 Jul 2013 Link to this post

    Hi Paul,

    I cannot bind to a specific release date since the demand for this feature is quite low. In addition, we have some concerns regarding this functionality as it might bring unwanted side effects to the existing behavior of RadListPIcker. I'll have to discuss this with the product team but the earliest we could consider implementing this feature would be after the official Q3 2013 release (mid. October).

    Regards,
    Kiril Stanoev
    Telerik
    Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
  6. Paul Wade
    Paul Wade avatar
    8 posts
    Member since:
    Oct 2008

    Posted 31 Jul 2013 Link to this post

    Thanks for the help and info Kiril. I guess I can live with it :)
  7. Paul Wade
    Paul Wade avatar
    8 posts
    Member since:
    Oct 2008

    Posted 31 Jul 2013 Link to this post

    For anyone interested here is a quick implementation of the list picker with a bindable selected items

    public class ListPickerWSelected : RadListPicker




    {

     



    public static readonly DependencyProperty BindableSelectedItemsProperty =

    DependencyProperty.Register("BindableSelectedItems", typeof(IList), typeof(ListPickerWSelected), new PropertyMetadata(default(IList)));

    protected override void OnSelectionChanged(SelectionChangedEventArgs args)



    {



    base.OnSelectionChanged(args);

    BindableSelectedItems = this.SelectedItems;



    }



    public IList BindableSelectedItems



    {



    get { return (IList)GetValue(BindableSelectedItemsProperty); }

    set { SetValue(BindableSelectedItemsProperty, value); }



    }

    }



Back to Top
DevCraft banner