示例#1
0
        private static void OnItemsSourceChanged(BindableObject bindable, object oldValue, object newValue)
        {
            XLabsExtendedPicker bindablePicker = (XLabsExtendedPicker)bindable;

            bindablePicker.ItemsSource = (IList)newValue;
            loadItemsAndSetSelected(bindable);
        }
示例#2
0
        private static void OnDisplayPropertyChanged(BindableObject bindable, object oldValue, object newValue)
        {
            XLabsExtendedPicker bindablePicker = (XLabsExtendedPicker)bindable;

            bindablePicker.DisplayProperty = (string)newValue;
            loadItemsAndSetSelected(bindable);
        }
示例#3
0
        private static void OnSelectedItemChanged(BindableObject bindable, object oldValue, object newValue)
        {
            XLabsExtendedPicker bindablePicker = (XLabsExtendedPicker)bindable;

            bindablePicker.SelectedItem = newValue;
            if (bindablePicker.ItemsSource != null && bindablePicker.SelectedItem != null)
            {
                int count = 0;
                foreach (object obj in bindablePicker.ItemsSource)
                {
                    if (obj == bindablePicker.SelectedItem)
                    {
                        bindablePicker.SelectedIndex = count;
                        break;
                    }
                    count++;
                }
            }
        }
示例#4
0
        static void loadItemsAndSetSelected(BindableObject bindable)
        {
            XLabsExtendedPicker bindablePicker = (XLabsExtendedPicker)bindable;

            if (bindablePicker.ItemsSource as IEnumerable != null)
            {
                PropertyInfo propertyInfo = null;
                int          count        = 0;
                foreach (object obj in (IEnumerable)bindablePicker.ItemsSource)
                {
                    string value = string.Empty;
                    if (bindablePicker.DisplayProperty != null)
                    {
                        if (propertyInfo == null)
                        {
                            propertyInfo = obj.GetType().GetRuntimeProperty(bindablePicker.DisplayProperty);
                            if (propertyInfo == null)
                            {
                                throw new Exception(String.Concat(bindablePicker.DisplayProperty, " is not a property of ", obj.GetType().FullName));
                            }
                        }
                        value = propertyInfo.GetValue(obj).ToString();
                    }
                    else
                    {
                        value = obj.ToString();
                    }
                    bindablePicker.Items.Add(value);
                    if (bindablePicker.SelectedItem != null)
                    {
                        if (bindablePicker.SelectedItem == obj)
                        {
                            bindablePicker.SelectedIndex = count;
                        }
                    }
                    count++;
                }
            }
        }