protected virtual void SelectLassoComponents(Rectangle lasso)//TODO: make hit test strategy pluggable { double left = lasso.GetValue <double>(Canvas.LeftProperty); double top = lasso.GetValue <double>(Canvas.TopProperty); double width = lasso.Width; double height = lasso.Height; Rect r = new Rect(left, top, width, height); List <IDesignableControl> selection = new List <IDesignableControl>(); foreach (var u in LayoutRoot.Children) { if (u is IDesignableControl) { IDesignableControl test = (IDesignableControl)u; Point[] corners = test.Visual.GetCanvasCorners(); for (int i = 0; i < corners.Length; ++i) { if (r.Contains(corners[i])) { selection.Add(test); break; } } } } SelectionSvc.Select(selection); }
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 string GetUniqueName(INamingContainer container, IDesignableControl newChild) { var type = newChild.GetType(); string namePart = type.Name; int existingCount = (from c in container.Children where c.GetType() == type select c).Count(); return(namePart + existingCount); }
private void EnsureName(IDesignableControl dc) { if (string.IsNullOrEmpty(dc.DesignTimeName)) { string name = NameProvider.GetUniqueName(this, ((DesignSite)dc).HostedContent); dc.DesignTimeName = name; } }
/// <summary> /// Setup bindings etc. /// </summary> /// <param name="instance"></param> /// <param name="desc"></param> public void Initialize(IDesignableControl instance, DamonPayne.AGT.Design.Types.DesignablePropertyDescriptor desc) { Binding b = new Binding("Softness"); b.Converter = desc.Converter; b.Mode = BindingMode.TwoWay; b.Source = instance; Slider.SetBinding(Slider.ValueProperty, b); }
public void OnDrop(IDesignableControl dc) { EnsureName(dc); dc.Visual.SetValue(Canvas.LeftProperty, _localMousePos.X); dc.Visual.SetValue(Canvas.TopProperty, _localMousePos.Y); LayoutRoot.Children.Add(dc.Visual); if (dc is DamonPayne.AGT.Design.Controls.DesignSite) { ((DamonPayne.AGT.Design.Controls.DesignSite)dc).DesignParent = this; } }
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); } }
public IDesignableControl CreateInstance(Type t) { if (!t.ImplementsInterface(typeof(IDesignableControl))) { throw new ArgumentException(t + " does not implement IDesignableControl"); } IDesignableControl idc = null; idc = (IDesignableControl)Activator.CreateInstance(t); DesignSite site = new DesignSite(); site.HostedContent = idc; return(site); }
public virtual void EndDrag(MouseButtonEventArgs e) { RegionManager.TopLevelContainer.Children.Remove(_dragRepresentation); _dragRepresentation = null; foreach (IDropTarget target in _dropTargets) { if (target.IsHitTestVisible) { IEnumerable <UIElement> elements = target.HitTest(_mousePos); if (elements.GetEnumerator().MoveNext())//hit test succeed { IDesignableControl ctrl = DesignCreator.CreateInstance(_draggingType); target.OnDrop(ctrl); } } } _draggingType = null; }
/// <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); }
protected virtual void EditSingle(IDesignableControl idt) { List <DesignablePropertyDescriptor> props = Inspector.Inspect(idt); Model.SetProperties(props); var propCount = 0; foreach (var descriptor in props) { _propertyPart.RowDefinitions.Add(new RowDefinition()); TextBlock tb = new TextBlock(); tb.Text = descriptor.DisplayName; tb.SetValue(Grid.RowProperty, propCount); tb.SetValue(Grid.ColumnProperty, 0); tb.Style = _descriptionTextBlockStyle; // FrameworkElement displayElement = EditServiceHelper.GetDisplayInstance(idt, descriptor); if (null == displayElement) { displayElement = new TextBlock { Text = "No display element found" }; } displayElement.SetValue(Grid.RowProperty, propCount); displayElement.SetValue(Grid.ColumnProperty, 1); displayElement.GotFocus += new RoutedEventHandler(displayElement_GotFocus); displayElement.MouseLeftButtonDown += new MouseButtonEventHandler(displayElement_MouseLeftButtonDown); Model.SetDisplayElement(descriptor, displayElement); _propertyPart.Children.Add(tb); _propertyPart.Children.Add(displayElement); ++propCount; } }
/// <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); }
public System.Collections.Generic.List <DesignablePropertyDescriptor> Inspect(IDesignableControl idt) { if (null != idt) { return(idt.GetDesignProperties()); } return(null); }