This is a migrated thread and some comments may be shown as answers.

ListPicker Selected items binding

5 Answers 95 Views
ListPicker
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Paul Wade
Top achievements
Rank 1
Paul Wade asked on 24 Jul 2013, 05:43 PM
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);
            }
        }
    }


5 Answers, 1 is accepted

Sort by
0
Kiril Stanoev
Telerik team
answered on 29 Jul 2013, 08:50 AM
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.
0
Paul Wade
Top achievements
Rank 1
answered on 30 Jul 2013, 02:51 PM

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?

0
Kiril Stanoev
Telerik team
answered on 31 Jul 2013, 01:55 PM
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.
0
Paul Wade
Top achievements
Rank 1
answered on 31 Jul 2013, 02:41 PM
Thanks for the help and info Kiril. I guess I can live with it :)
0
Paul Wade
Top achievements
Rank 1
answered on 31 Jul 2013, 06:29 PM

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



}

}



Tags
ListPicker
Asked by
Paul Wade
Top achievements
Rank 1
Answers by
Kiril Stanoev
Telerik team
Paul Wade
Top achievements
Rank 1
Share this question
or