public override void InitializeDefaults(DesignItem item) { //Not every Content Control can have a text as Content (e.g. ZoomBox of WPF Toolkit) if (item.Component is Button) { DesignItemProperty contentProperty = item.Properties["Content"]; if (contentProperty.ValueOnInstance == null) { contentProperty.SetValue(item.ComponentType.Name); } } DesignItemProperty verticalAlignmentProperty = item.Properties["VerticalAlignment"]; if (verticalAlignmentProperty.ValueOnInstance == null) { verticalAlignmentProperty.SetValue(VerticalAlignment.Center); } DesignItemProperty horizontalAlignmentProperty = item.Properties["HorizontalAlignment"]; if (horizontalAlignmentProperty.ValueOnInstance == null) { horizontalAlignmentProperty.SetValue(HorizontalAlignment.Center); } }
public override void InitializeDefaults(DesignItem item) { DesignItemProperty textProperty = item.Properties["Text"]; if (textProperty.ValueOnInstance == null || textProperty.ValueOnInstance.ToString() == "") { textProperty.SetValue(item.ComponentType.Name); item.Properties[FrameworkElement.WidthProperty].Reset(); item.Properties[FrameworkElement.HeightProperty].Reset(); } DesignItemProperty verticalAlignmentProperty = item.Properties["VerticalAlignment"]; if (verticalAlignmentProperty.ValueOnInstance == null) { verticalAlignmentProperty.SetValue(VerticalAlignment.Center); } DesignItemProperty horizontalAlignmentProperty = item.Properties["HorizontalAlignment"]; if (horizontalAlignmentProperty.ValueOnInstance == null) { horizontalAlignmentProperty.SetValue(HorizontalAlignment.Center); } }
public void CreateEventHandler(DesignItemProperty eventProperty) { string handlerName = (string)eventProperty.ValueOnInstance; if (string.IsNullOrEmpty(handlerName)) { var item = eventProperty.DesignItem; if (string.IsNullOrEmpty(item.Name)) { GenerateName(eventProperty.DesignItem); } handlerName = item.Name + "_" + eventProperty.Name; eventProperty.SetValue(handlerName); } IType t = GetDesignedClass(SD.ParserService.GetCompilation(FindProjectContainingFile())); if (t != null) { IMethod method = t.GetMethods(m => m.Name == handlerName).FirstOrDefault(); if (method != null) { FileService.JumpToFilePosition(method.Region.FileName, method.Region.BeginLine, method.Region.BeginColumn); return; } } IProject p = FindProjectContainingFile(); ITypeDefinition c = t.GetDefinition(); if (p != null && c != null) { var e = FindEventDeclaration(c.Compilation, eventProperty.DeclaringType, eventProperty.Name); p.LanguageBinding.CodeGenerator.InsertEventHandler(c, handlerName, e, true); } }
public void AddTypeAsResource(object component, string expectedXamlValue, string typePrefix, String[] additionalXmlns) { DesignItem textBlock = CreateCanvasContext("<TextBlock/>"); DesignItem canvas = textBlock.Parent; DesignItemProperty canvasResources = canvas.Properties.GetProperty("Resources"); DesignItem componentItem = canvas.Services.Component.RegisterComponentForDesigner(component); componentItem.Key = "res1"; Assert.IsTrue(canvasResources.IsCollection); canvasResources.CollectionElements.Add(componentItem); DesignItemProperty prop = textBlock.Properties[TextBlock.TagProperty]; prop.SetValue(new StaticResourceExtension()); prop.Value.Properties["ResourceKey"].SetValue("res1"); string typeName = component.GetType().Name; string expectedXaml = "<Canvas.Resources>\n" + " <" + typePrefix + typeName + " x:Key=\"res1\">" + expectedXamlValue + "</" + typePrefix + typeName + ">\n" + "</Canvas.Resources>\n" + "<TextBlock Tag=\"{StaticResource res1}\" />"; AssertCanvasDesignerOutput(expectedXaml, textBlock.Context, additionalXmlns); AssertLog(""); }
public void AddNativeTypeAsResource(object component, string expectedXamlValue) { DesignItem textBlock = CreateCanvasContext("<TextBlock/>"); DesignItem canvas = textBlock.Parent; DesignItemProperty canvasResources = canvas.Properties.GetProperty("Resources"); DesignItem componentItem = canvas.Services.Component.RegisterComponentForDesigner(component); componentItem.Key = "res1"; Assert.IsTrue(canvasResources.IsCollection); canvasResources.CollectionElements.Add(componentItem); DesignItemProperty prop = textBlock.Properties[TextBlock.TagProperty]; prop.SetValue(new StaticResourceExtension()); prop.Value.Properties["ResourceKey"].SetValue("res1"); string typeName = component.GetType().Name; string expectedXaml = "<Canvas.Resources>\n" + " <Controls0:" + typeName + " x:Key=\"res1\">" + expectedXamlValue + "</Controls0:" + typeName + ">\n" + "</Canvas.Resources>\n" + "<TextBlock Tag=\"{StaticResource ResourceKey=res1}\" />"; AssertCanvasDesignerOutput(expectedXaml, textBlock.Context, "xmlns:Controls0=\"clr-namespace:System;assembly=mscorlib\""); AssertLog(""); }
public override void InitializeDefaults(DesignItem item) { DesignItemProperty fillProperty = item.Properties["Fill"]; if (fillProperty.ValueOnInstance == null) { fillProperty.SetValue(Brushes.YellowGreen); } }
public override void InitializeDefaults(DesignItem item) { DesignItemProperty contentProperty = item.Properties["Content"]; if (contentProperty.ValueOnInstance == null) { contentProperty.SetValue(item.ComponentType.Name); } }
void SetGridLengthUnit(GridUnitType unit, DesignItem item, DependencyProperty property) { DesignItemProperty itemProperty = item.Properties[property]; GridLength oldValue = (GridLength)itemProperty.ValueOnInstance; GridLength value = GetNewGridLength(unit, oldValue); if (value != oldValue) { itemProperty.SetValue(value); } }
public void CreateEventHandler(DesignItemProperty eventProperty) { var item = eventProperty.DesignItem; string handlerName = (string)eventProperty.ValueOnInstance; if (string.IsNullOrEmpty(handlerName)) { if (string.IsNullOrEmpty(item.Name)) { GenerateName(eventProperty.DesignItem); } handlerName = item.Name + "_" + eventProperty.Name; eventProperty.SetValue(handlerName); } CreateEventHandlerInternal(eventProperty.ReturnType, handlerName); }
public override void InitializeDefaults(DesignItem item) { DesignItemProperty headerProperty = item.Properties["Header"]; if (headerProperty.ValueOnInstance == null) { headerProperty.SetValue(item.ComponentType.Name); } DesignItemProperty contentProperty = item.Properties["Content"]; if (contentProperty.ValueOnInstance == null) { contentProperty.SetValue(new PanelInstanceFactory().CreateInstance(typeof(Canvas))); } }
public void CreateEventHandler(DesignItemProperty eventProperty) { var item = eventProperty.DesignItem; string handlerName = (string)eventProperty.ValueOnInstance; if (string.IsNullOrEmpty(handlerName)) { if (string.IsNullOrEmpty(item.Name)) { GenerateName(eventProperty.DesignItem); } handlerName = item.Name + "_" + eventProperty.Name; eventProperty.SetValue(handlerName); } CreateEventHandlerInternal(eventProperty.ReturnType, handlerName); }
public void CreateEventHandler(DesignItemProperty eventProperty) { string handlerName = (string)eventProperty.ValueOnInstance; if (string.IsNullOrEmpty(handlerName)) { var item = eventProperty.DesignItem; if (string.IsNullOrEmpty(item.Name)) { GenerateName(eventProperty.DesignItem); } handlerName = item.Name + "_" + eventProperty.Name; eventProperty.SetValue(handlerName); } IType t = GetDesignedClass(SD.ParserService.GetCompilation(FindProjectContainingFile())); if (t != null) { IMethod method = t.GetMethods(m => m.Name == handlerName).FirstOrDefault(); if (method != null) { FileService.JumpToFilePosition(method.Region.FileName, method.Region.BeginLine, method.Region.BeginColumn); return; } } IProject p = FindProjectContainingFile(); ITypeDefinition c = t.GetDefinition(); if (p != null && c != null) { var e = FindEventDeclaration(c.Compilation, eventProperty.DeclaringType, eventProperty.Name); p.LanguageBinding.CodeGenerator.InsertEventHandler(c, handlerName, e, true); } }
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { var val = value; if (_converter != null) { val = _converter.ConvertBack(value, targetType, parameter, culture); } var changeGroup = _designItem.OpenGroup("Property: " + _propertyName); try { DesignItemProperty property = null; if (_property != null) { try { property = _designItem.Properties.GetProperty(_property); } catch (Exception) { property = _designItem.Properties.GetAttachedProperty(_property); } } else { property = _designItem.Properties.GetProperty(_propertyName); } property.SetValue(val); if (!_singleItemProperty && _designItem.Services.Selection.SelectedItems.Count > 1) { var msg = MessageBoxResult.Yes; if (_askWhenMultipleItemsSelected) { msg = MessageBox.Show("Apply changes to all selected Items", "", MessageBoxButton.YesNo); } if (msg == MessageBoxResult.Yes) { foreach (var item in _designItem.Services.Selection.SelectedItems) { try { if (_property != null) { property = item.Properties.GetProperty(_property); } else { property = item.Properties.GetProperty(_propertyName); } } catch (Exception) { } if (property != null) { property.SetValue(val); } } } } changeGroup.Commit(); } catch (Exception) { changeGroup.Abort(); } return(val); }