Esempio n. 1
0
        private static void OnItemsSourceChanged(BindableObject bindable, object oldValue, object newValue)
        {
            BindablePicker picker = (BindablePicker)bindable;

            if (picker.CanHaveAll && oldValue is IList && newValue is IList &&
                (((IList)oldValue).Count + 1) == (((IList)newValue).Count))
            {
                //This is if we just added the new one already
            }
            else if (picker.CanHaveAll)
            {
                var objectList = new List <object>();
                objectList.Add(picker.AllTitle);
                foreach (var item in ((IList)newValue))
                {
                    objectList.Add(item);
                }
                picker.ItemsSource = objectList;
            }
            else
            {
                picker.ItemsSource = (IList)newValue;
            }

            loadItemsAndSetSelected(bindable);
        }
Esempio n. 2
0
        private static void OnDisplayPropertyChanged(BindableObject bindable, object oldValue, object newValue)
        {
            BindablePicker picker = (BindablePicker)bindable;

            picker.DisplayProperty = (string)newValue;
            loadItemsAndSetSelected(bindable);
        }
Esempio n. 3
0
        private static void OnItemsSourceChanged(BindableObject bindable, object oldValue, object newValue)
        {
            BindablePicker picker = (BindablePicker)bindable;

            picker.ItemsSource = (IList)newValue;

            loadItemsAndSetSelected(bindable);
        }
Esempio n. 4
0
        static void loadItemsAndSetSelected(BindableObject bindable)
        {
            BindablePicker picker = (BindablePicker)bindable;

            if (picker.ItemsSource as IEnumerable != null)
            {
                picker.disableEvents = true;
                picker.SelectedIndex = -1;
                picker.Items.Clear();
                int count = 0;
                foreach (object obj in (IEnumerable)picker.ItemsSource)
                {
                    string value = string.Empty;
                    if (picker.DisplayProperty != null)
                    {
                        var prop = obj.GetType().GetRuntimeProperties().FirstOrDefault(p => string.Equals(p.Name, picker.DisplayProperty, StringComparison.OrdinalIgnoreCase));
                        if (prop != null)
                        {
                            value = prop.GetValue(obj).ToString();
                        }
                        else
                        {
                            value = obj.ToString();
                        }
                    }
                    else
                    {
                        value = obj.ToString();
                    }
                    picker.Items.Add(value);
                    if (picker.SelectedItem != null)
                    {
                        if (picker.SelectedItem == obj)
                        {
                            picker.SelectedIndex = count;
                        }
                    }
                    count++;
                }
                picker.disableEvents = false;
            }
            else
            {
                picker.Items.Clear();
            }
        }
Esempio n. 5
0
        private static void OnSelectedItemChanged(BindableObject bindable, object oldValue, object newValue)
        {
            BindablePicker picker = (BindablePicker)bindable;

            picker.SelectedItem = newValue;
            if (picker.ItemsSource != null && picker.SelectedItem != null)
            {
                int count = 0;
                foreach (object obj in picker.ItemsSource)
                {
                    if (obj == picker.SelectedItem)
                    {
                        picker.SelectedIndex = count;
                        break;
                    }
                    count++;
                }
            }
        }