예제 #1
0
        private static void OnDisplayPropertyChanged(BindableObject bindable, object oldValue, object newValue)
        {
            ExtendedPicker bindablePicker = (ExtendedPicker)bindable;

            bindablePicker.DisplayProperty = (string)newValue;
            loadItemsAndSetSelected(bindable);
        }
예제 #2
0
        private static void OnItemsSourceChanged(BindableObject bindable, object oldValue, object newValue)
        {
            ExtendedPicker bindablePicker = (ExtendedPicker)bindable;

            bindablePicker.ItemsSource = (IList)newValue;
            loadItemsAndSetSelected(bindable);
        }
        public App()
        {
            var extenderPicker = new ExtendedPicker ();
            extenderPicker.ItemsSource = new List<Color>{ Color.Aqua, Color.Black };

            // The root page of your application
            MainPage = new ExtendedPickerPage();
        }
예제 #4
0
        private static void OnSelectedItemChanged(BindableObject bindable, object oldValue, object newValue)
        {
            ExtendedPicker bindablePicker = (ExtendedPicker)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++;
                }
            }
        }
        public ExtendedPickerPage()
        {
            InitializeComponent ();
            BindingContext = this;
            myPicker = new ExtendedPicker (){DisplayProperty = "FirstName"};
            myPicker.SetBinding(ExtendedPicker.ItemsSourceProperty,new Binding("MyDataList",BindingMode.TwoWay));
            myPicker.SetBinding(ExtendedPicker.SelectedItemProperty,new Binding("TheChosenOne",BindingMode.TwoWay));
            myStackLayout.Children.Add (new Label{ Text = "Code Created:" });
            myStackLayout.Children.Add (myPicker);

            TheChosenOne = new DataClass(){ FirstName = "Jet", LastName = "Li" };
            MyDataList = new ObservableCollection<object> () {
                new DataClass(){FirstName="Jack",LastName="Doe"},
                TheChosenOne,
                new DataClass(){FirstName="Matt",LastName="Bar"},
                new DataClass(){FirstName="Mic",LastName="Jaggery"},
                new DataClass(){FirstName="Michael",LastName="Jackon"}
            };
        }
예제 #6
0
        static void loadItemsAndSetSelected(BindableObject bindable)
        {
            ExtendedPicker bindablePicker = (ExtendedPicker)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++;
                }
            }
        }
        private static void OnSelectedItemChanged(BindableObject bindable, object oldValue, object newValue)
        {
            ExtendedPicker bindablePicker = (ExtendedPicker)bindable;
            ExtendedPicker picker         = bindable as ExtendedPicker;

            if (picker != null)
            {
                var selectedItem = picker.ItemsSource[picker.SelectedIndex];
                if (!string.IsNullOrWhiteSpace(picker.KeyMemberPath))
                {
                    var keyProperty = selectedItem.GetType().GetRuntimeProperty(picker.KeyMemberPath);
                    if (keyProperty == null)
                    {
                        throw new InvalidOperationException(String.Concat(picker.KeyMemberPath, " is not a property of ",
                                                                          selectedItem.GetType().FullName));
                    }
                    picker.SelectedItem = keyProperty.GetValue(selectedItem);
                }
                else
                {
                    picker.SelectedItem = selectedItem.ToString();
                }
            }
            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++;
                }
            }
        }
        private static void OnKeyMemberPathChanged(BindableObject bindable, object oldValue, object newValue)
        {
            ExtendedPicker picker = bindable as ExtendedPicker;

            picker.KeyMemberPath = newValue?.ToString();
        }
예제 #9
0
		private static void OnItemsSourceChanged(BindableObject bindable, object oldValue, object newValue)
		{
			bindablePicker = (ExtendedPicker)bindable;
			bindablePicker.ItemsSource = (IList)newValue;
			loadItems(bindable);

			observable = newValue as INotifyCollectionChanged;
			if (observable != null)
			{
				observable.CollectionChanged += observable_CollectionChanged;
			}

		}