private FrameworkElement CreateBindableMultipleSelectControl(PropertyItem pi, string lookupKey) { var control = new ListBoxWrapper(); var data = pi.Converter.Convert(pi.ItemsSource, typeof(IList <string>), null, null) as IList <string>; control.AllItems = data; control.InitSelectedItemsViewModel = null; ReferenceLookupList.RegisterListUpdateEventHandler(lookupKey, (sender, args) => { var list = ReferenceLookupList.GetCompleteList(lookupKey); var data1 = pi.Converter.Convert(list, typeof(IList <string>), null, null) as IList <string>; control.AllItems = data1; }); var selectedItemBinding = pi.CreateBinding(); selectedItemBinding.Mode = BindingMode.TwoWay; control.SetBinding(ListBoxWrapper.SelectedItemsProperty, selectedItemBinding); //var initSelectedBinding = pi.CreateOneWayBinding(); //control.SetBinding(ListBoxWrapper.InitSelectedItemsProperty, initSelectedBinding); return(control); //return base.CreateDefaultControl(pi); }
private FrameworkElement CreateBindableComboBoxControl(PropertyItem pi, string lookupKey) { var cbx = new ComboBox(); var itemsSourceBinding = pi.CreateOneWayBinding(); itemsSourceBinding.Path = null; itemsSourceBinding.Source = pi.ItemsSource; cbx.SetBinding(ItemsControl.ItemsSourceProperty, itemsSourceBinding); ReferenceLookupList.RegisterListUpdateEventHandler(lookupKey, (sender, args) => { var list = ReferenceLookupList.GetCompleteList(lookupKey); var itemsSourceBinding1 = pi.CreateOneWayBinding(); itemsSourceBinding1.Path = null; itemsSourceBinding1.Source = list; cbx.SetBinding(ItemsControl.ItemsSourceProperty, itemsSourceBinding1); }); var selectedItemBinding = pi.CreateBinding(); selectedItemBinding.Mode = BindingMode.TwoWay; //selectedItemBinding.Path = new PropertyPath("Selected"); cbx.SetBinding(Selector.SelectedItemProperty, selectedItemBinding); return(cbx); }
public override FrameworkElement CreateControl(PropertyItem pi, PropertyControlFactoryOptions options) { FrameworkElement retval = null; if (pi.Is(typeof(CommandProperty))) { pi.HeaderPlacement = HeaderPlacement.Collapsed; retval = CreateCommandLinkControl(pi); } else if (pi.GetAttribute <NestedPropertiesAttribute>() != null) { if (pi.Is(typeof(ICollection)) || pi.Is(typeof(ICollection <>))) { retval = CreateNestedPropertyGridsControl(pi); } else { retval = CreateNestedPropertyGridControl(pi); } } else { var rla = pi.GetAttribute <ReferenceLookupAttribute>(); if (rla != null) { if (pi.Is(typeof(string))) { pi.Converter = new ReferenceListLookupConverter { LookupKey = rla.LookupKey }; pi.ItemsSource = ReferenceLookupList.GetCompleteList(rla.LookupKey); retval = this.CreateBindableComboBoxControl(pi, rla.LookupKey); } else if (pi.Is(typeof(IEnumerable))) { pi.Converter = new ReferenceListLookupConverter { LookupKey = rla.LookupKey }; pi.ItemsSource = ReferenceLookupList.GetCompleteList(rla.LookupKey); retval = this.CreateBindableMultipleSelectControl(pi, rla.LookupKey); } else { pi.Converter = new ReferenceLookupConverter { LookupKey = rla.LookupKey }; retval = base.CreateDefaultControl(pi); } } else { retval = base.CreateControl(pi, options); } } retval.Name = pi.Descriptor.Name + "PropertyPageElem"; return(retval); }