public static FrameworkElement GetEditInstance(IDesignableControl instance, DesignablePropertyDescriptor desc) { if (!desc.Editable) { return(null); } if (null == desc.EditorType || _basicBindableEditTypes.ContainsKey(desc.EditorType)) { Type editType = _editors[desc.PropertyInfo.PropertyType]; FrameworkElement editInstance = null; editInstance = (FrameworkElement)Activator.CreateInstance(editType); if (editInstance is ItemsControl && desc.SupportsStandardValues) { SetupItemsValues(desc, (ItemsControl)editInstance); } SetupEditInstanceBinding(instance, desc, editInstance); return(editInstance); } else if (desc.EditorType.ImplementsInterface(typeof(IDesignablePropertyEditor))) { var editor = (IDesignablePropertyEditor)Activator.CreateInstance(desc.EditorType); editor.Initialize(instance, desc); return(editor.Visual); } return(null); }
public List <DesignablePropertyDescriptor> GetDesignProperties() { List <DesignablePropertyDescriptor> props = EditServiceHelper.GetDefaultDescriptors(); DesignablePropertyDescriptor fillColor = new DesignablePropertyDescriptor(); fillColor.PropertyInfo = GetType().GetProperty("FillColor"); fillColor.DisplayName = "Color"; fillColor.DisplayType = typeof(TextBlock); fillColor.Editable = true; fillColor.EditorType = typeof(ComboBox); fillColor.SupportsStandardValues = true; fillColor.StandardValues = new List <object>(new object[] { Colors.Purple, Colors.Red, Colors.Gray, Colors.Brown, Colors.Blue, Colors.Green, Colors.Orange }); fillColor.Converter = new DamonPayne.AGT.Design.Converters.ColorConverter(); props.Add(fillColor); DesignablePropertyDescriptor softness = new DesignablePropertyDescriptor(); softness.DisplayName = "Softness"; softness.Converter = null; softness.DisplayType = typeof(SoftnessVisualizer); softness.Editable = true; softness.EditorType = typeof(SoftnessEditor); softness.PropertyInfo = GetType().GetProperty("Softness"); props.Add(softness); return(props); }
protected virtual void SwapToDisplay(DesignablePropertyDescriptor desc, FrameworkElement editElement) { var display = Model.GetDisplayElement(desc); if (null != display)//Safety { _propertyPart.Children.Remove(editElement); _propertyPart.Children.Add(display); } }
protected static void SetupEditInstanceBinding(IDesignableControl instance, DesignablePropertyDescriptor desc, FrameworkElement editor) { if (_basicBindableEditTypes.ContainsKey(editor.GetType())) { var dProp = _basicBindableEditTypes[editor.GetType()]; Binding b = new Binding(desc.PropertyInfo.Name); b.Converter = desc.Converter; b.Mode = BindingMode.TwoWay; b.Source = instance; editor.SetBinding(dProp, b); } }
/// <summary> /// Returns common props from IDesignableControl : DesignTimeName, /// </summary> /// <returns></returns> public static List <DesignablePropertyDescriptor> GetDefaultDescriptors() { List <DesignablePropertyDescriptor> common = new List <DesignablePropertyDescriptor>(); DesignablePropertyDescriptor name = new DesignablePropertyDescriptor(); name.PropertyInfo = typeof(IDesignableControl).GetProperty("DesignTimeName"); name.DisplayName = "Name"; name.Editable = true; common.Add(name); return(common); }
protected virtual void SwapToEdit(DesignablePropertyDescriptor desc, FrameworkElement editElement) { var display = Model.GetDisplayElement(desc); if (null != editElement) { int row = display.GetValue <int>(Grid.RowProperty); int col = display.GetValue <int>(Grid.ColumnProperty); editElement.SetValue(Grid.RowProperty, row); editElement.SetValue(Grid.ColumnProperty, col); _propertyPart.Children.Remove(display); _propertyPart.Children.Add(editElement); } }
/// <summary> /// Return default <code>DesignablePropertyDescriptor</code> objects for each Property name /// </summary> /// <param name="names"></param> /// <returns></returns> public static List <DesignablePropertyDescriptor> GetDescriptors(IEnumerable <string> names, IDesignableControl idc) { List <DesignablePropertyDescriptor> props = new List <DesignablePropertyDescriptor>(); Type t = idc.GetType(); foreach (string s in names) { var dp = new DesignablePropertyDescriptor(); dp.DisplayName = s; dp.Editable = true; dp.PropertyInfo = t.GetProperty(s); props.Add(dp); } return(props); }
/// <summary> /// Populate List Item with appropriate .... ? /// </summary> /// <param name="desc"></param> /// <param name="editor"></param> protected static void SetupItemsValues(DesignablePropertyDescriptor desc, ItemsControl editor) { if (null != desc.Converter) { List <object> vals = new List <object>();//TODO, is copy & run converter really the best option here? Type t = desc.PropertyInfo.PropertyType; foreach (object o in desc.StandardValues) { var converted = desc.Converter.Convert(o, typeof(string), null, null); vals.Add(converted); } editor.ItemsSource = vals; } else { editor.ItemsSource = desc.StandardValues; } }
/// <summary> /// /// </summary> /// <param name="instance"></param> /// <param name="desc"></param> /// <returns></returns> public static FrameworkElement GetDisplayInstance(IDesignableControl instance, DesignablePropertyDescriptor desc) { //if null we try to find a default, otherwise see if we can do a binding anyway using the override if (null == desc.DisplayType || _basicBindableDisplayTypes.ContainsKey(desc.DisplayType)) { Type displayType = _displayors[desc.PropertyInfo.PropertyType]; FrameworkElement displayInstance = null; if (null != displayType) { displayInstance = (FrameworkElement)Activator.CreateInstance(displayType); SetupDisplayInstanceBinding(instance, desc, displayInstance); } return(displayInstance); } else if (desc.DisplayType.ImplementsInterface(typeof(IDesignablePropertyVisualizer))) { var visualizer = (IDesignablePropertyVisualizer)Activator.CreateInstance(desc.DisplayType); visualizer.Initialize(instance, desc); return(visualizer.Visual); } return(null); }