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 AddStaticResourceWhereResourceOnSameElement() { DesignItem button = CreateCanvasContext("<Button/>"); DesignItem canvas = button.Parent; DesignItemProperty resProp = button.Properties.GetProperty("Resources"); Assert.IsTrue(resProp.IsCollection); DesignItem exampleClassItem = canvas.Services.Component.RegisterComponentForDesigner(new ExampleClass()); exampleClassItem.Key = "res1"; resProp.CollectionElements.Add(exampleClassItem); button.Properties["Tag"].SetValue(new StaticResourceExtension()); button.Properties["Tag"].Value.Properties["ResourceKey"].SetValue("res1"); string expectedXaml = "<Button>\n" + " <Button.Resources>\n" + " <t:ExampleClass x:Key=\"res1\" />\n" + " </Button.Resources>\n" + " <Button.Tag>\n" + " <StaticResourceExtension ResourceKey=\"res1\" />\n" + " </Button.Tag>\n" + "</Button>"; AssertCanvasDesignerOutput(expectedXaml, button.Context); AssertLog(""); }
/// <summary> /// Creates a property editor for the specified <paramref name="property"/> /// </summary> public static FrameworkElement CreateEditor(DesignItemProperty property) { Type editorType; if (!propertyEditors.TryGetValue(property.FullName, out editorType)) { var type = property.ReturnType; while (type != null) { if (typeEditors.TryGetValue(type, out editorType)) { break; } type = type.BaseType; } foreach (var t in typeEditors) { if (t.Key.IsAssignableFrom(property.ReturnType)) { return (FrameworkElement)Activator.CreateInstance(t.Value); } } if (editorType == null) { var standardValues = Metadata.GetStandardValues(property.ReturnType); if (standardValues != null) { return new ComboBoxEditor() { ItemsSource = standardValues }; } return new TextBoxEditor(); } } return (FrameworkElement)Activator.CreateInstance(editorType); }
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 void AddMarkupExtensionWithoutWrapperToCollection() { DesignItem textBox = CreateCanvasContext("<TextBox/>"); DesignItem multiBindingItem = textBox.Context.Services.Component.RegisterComponentForDesigner(new System.Windows.Data.MultiBinding()); multiBindingItem.Properties["Converter"].SetValue(new ICSharpCode.WpfDesign.Tests.XamlDom.MyMultiConverter()); DesignItemProperty bindingsProp = multiBindingItem.ContentProperty; // MyBindingExtension is a markup extension that will not use a wrapper. DesignItem myBindingExtension = textBox.Context.Services.Component.RegisterComponentForDesigner(new ICSharpCode.WpfDesign.Tests.XamlDom.MyBindingExtension()); // Adding it to MultiBinding "Bindings" collection. bindingsProp.CollectionElements.Add(myBindingExtension); textBox.ContentProperty.SetValue(multiBindingItem); const string expectedXaml = "<TextBox>\n" + " <MultiBinding>\n" + " <MultiBinding.Converter>\n" + " <Controls0:MyMultiConverter />\n" + " </MultiBinding.Converter>\n" + " <Controls0:MyBindingExtension />\n" + " </MultiBinding>\n" + "</TextBox>"; AssertCanvasDesignerOutput(expectedXaml, textBox.Context, "xmlns:Controls0=\"" + ICSharpCode.WpfDesign.Tests.XamlDom.XamlTypeFinderTests.XamlDomTestsNamespace + "\""); AssertLog(""); }
/// <summary> /// Compares the positions of a and b in the model file. /// </summary> public static int ComparePositionInModelFile(DesignItem a, DesignItem b) { // first remember all parent properties of a HashSet <DesignItemProperty> aProps = new HashSet <DesignItemProperty>(); DesignItem tmp = a; while (tmp != null) { aProps.Add(tmp.ParentProperty); tmp = tmp.Parent; } // now walk up b's parent tree until a matching property is found tmp = b; while (tmp != null) { DesignItemProperty prop = tmp.ParentProperty; if (aProps.Contains(prop)) { if (prop.IsCollection) { return(prop.CollectionElements.IndexOf(a).CompareTo(prop.CollectionElements.IndexOf(b))); } else { return(0); } } tmp = tmp.Parent; } return(0); }
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 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 object GetDescription(DesignItemProperty property) { #warning reimplement this! /*IProjectContent pc = MyTypeFinder.GetProjectContent(file); * if (pc != null) { * // For attached Properties * if (property.DependencyFullName != null && property.Name.Contains(".")) { * IClass c = pc.GetClassByReflectionName(property.DependencyProperty.OwnerType.FullName, true); * if (c != null) { * IMember m = DefaultProjectContent.GetMemberByReflectionName(c, property.DependencyProperty.Name + "Property"); * if (m != null) * return CodeCompletionItem.ConvertDocumentation(m.Documentation); * } * } else { * IClass c = pc.GetClassByReflectionName(property.DeclaringType.FullName, true); * if (c != null) { * IMember m = DefaultProjectContent.GetMemberByReflectionName(c, property.Name); * if (m != null) * return CodeCompletionItem.ConvertDocumentation(m.Documentation); * } * } * }*/ return(null); }
public void AddBindingWithStaticResource() { DesignItem button = CreateCanvasContext("<Button/>"); DesignItem canvas = button.Parent; DesignItem textBox = canvas.Services.Component.RegisterComponentForDesigner(new TextBox()); canvas.Properties["Children"].CollectionElements.Add(textBox); DesignItemProperty resProp = canvas.Properties.GetProperty("Resources"); Assert.IsTrue(resProp.IsCollection); DesignItem exampleClassItem = canvas.Services.Component.RegisterComponentForDesigner(new ExampleClass()); exampleClassItem.Key = "bindingSource"; resProp.CollectionElements.Add(exampleClassItem); DesignItem bindingItem = canvas.Services.Component.RegisterComponentForDesigner(new Binding()); textBox.Properties[TextBox.TextProperty].SetValue(bindingItem); bindingItem.Properties["Path"].SetValue("StringProp"); bindingItem.Properties["Source"].SetValue(new StaticResourceExtension()); bindingItem.Properties["Source"].Value.Properties["ResourceKey"].SetValue("bindingSource"); string expectedXaml = "<Canvas.Resources>\n" + " <t:ExampleClass x:Key=\"bindingSource\" />\n" + "</Canvas.Resources>\n" + "<Button />\n" + "<TextBox Text=\"{Binding Path=StringProp, Source={StaticResource ResourceKey=bindingSource}}\" />"; AssertCanvasDesignerOutput(expectedXaml, button.Context); AssertLog(""); }
/// <summary> /// Creates a property editor for the specified <paramref name="property"/> /// </summary> public static FrameworkElement CreateEditor(DesignItemProperty property) { Type editorType; if (!propertyEditors.TryGetValue(property.FullName, out editorType)) { var type = property.ReturnType; while (type != null) { if (typeEditors.TryGetValue(type, out editorType)) { break; } type = type.BaseType; } if (editorType == null) { var standardValues = Metadata.GetStandardValues(property.ReturnType); if (standardValues != null) { return(new ComboBoxEditor() { ItemsSource = standardValues }); } return(new TextBoxEditor()); } } return((FrameworkElement)Activator.CreateInstance(editorType)); }
/// <summary> /// Creates a property editor for the specified <paramref name="property"/> /// </summary> public static FrameworkElement CreateEditor(DesignItemProperty property) { Type editorType; if (!propertyEditors.TryGetValue(property.FullName, out editorType)) { var type = property.ReturnType; while (type != null) { if (typeEditors.TryGetValue(type, out editorType)) { break; } type = type.BaseType; } foreach (var t in typeEditors) { if (t.Key.IsAssignableFrom(property.ReturnType)) { return (FrameworkElement)Activator.CreateInstance(t.Value); } } if (editorType == null) { var standardValues = Metadata.GetStandardValues(property.ReturnType); if (standardValues != null) { var itemsControl = (ItemsControl)Activator.CreateInstance(defaultComboboxEditor); itemsControl.ItemsSource = standardValues; if (Nullable.GetUnderlyingType(property.ReturnType) != null) { itemsControl.GetType().GetProperty("IsNullable").SetValue(itemsControl, true, null); //In this Class we don't know the Nullable Combo Box } return itemsControl; } return (FrameworkElement)Activator.CreateInstance(defaultTextboxEditor); } } return (FrameworkElement)Activator.CreateInstance(editorType); }
public void AddBrushAsResource() { DesignItem checkBox = CreateCanvasContext("<CheckBox/>"); DesignItem canvas = checkBox.Parent; DesignItemProperty canvasResources = canvas.Properties.GetProperty("Resources"); DesignItem brush = canvas.Services.Component.RegisterComponentForDesigner(new SolidColorBrush()); brush.Key = "testBrush"; brush.Properties[SolidColorBrush.ColorProperty].SetValue(Colors.Fuchsia); Assert.IsTrue(canvasResources.IsCollection); canvasResources.CollectionElements.Add(brush); checkBox.Properties[CheckBox.ForegroundProperty].SetValue(new StaticResourceExtension()); DesignItemProperty prop = checkBox.Properties[CheckBox.ForegroundProperty]; prop.Value.Properties["ResourceKey"].SetValue("testBrush"); string expectedXaml = "<Canvas.Resources>\n" + " <SolidColorBrush x:Key=\"testBrush\" Color=\"#FFFF00FF\" />\n" + "</Canvas.Resources>\n" + "<CheckBox Foreground=\"{StaticResource ResourceKey=testBrush}\" />"; AssertCanvasDesignerOutput(expectedXaml, checkBox.Context); AssertLog(""); }
public void AddStringAsResource() { DesignItem textBlock = CreateCanvasContext("<TextBlock/>"); DesignItem canvas = textBlock.Parent; DesignItemProperty canvasResources = canvas.Properties.GetProperty("Resources"); DesignItem str = canvas.Services.Component.RegisterComponentForDesigner("stringresource 1"); str.Key = "str1"; Assert.IsTrue(canvasResources.IsCollection); canvasResources.CollectionElements.Add(str); textBlock.Properties[TextBlock.TextProperty].SetValue(new StaticResourceExtension()); DesignItemProperty prop = textBlock.Properties[TextBlock.TextProperty]; prop.Value.Properties["ResourceKey"].SetValue("str1"); string expectedXaml = "<Canvas.Resources>\n" + " <Controls0:String x:Key=\"str1\">stringresource 1</Controls0:String>\n" + "</Canvas.Resources>\n" + "<TextBlock Text=\"{StaticResource ResourceKey=str1}\" />"; AssertCanvasDesignerOutput(expectedXaml, textBlock.Context, "xmlns:Controls0=\"clr-namespace:System;assembly=mscorlib\""); AssertLog(""); }
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); } }
/// <summary> /// Creates a property editor for the specified <paramref name="property"/> /// </summary> public static FrameworkElement CreateEditor(DesignItemProperty property) { Type editorType; if (!propertyEditors.TryGetValue(property.FullName, out editorType)) { var type = property.ReturnType; while (type != null) { if (typeEditors.TryGetValue(type, out editorType)) { break; } type = type.BaseType; } foreach (var t in typeEditors) { if (t.Key.IsAssignableFrom(property.ReturnType)) { return((FrameworkElement)Activator.CreateInstance(t.Value)); } } if (editorType == null) { var standardValues = Metadata.GetStandardValues(property.ReturnType); if (standardValues != null) { var itemsControl = (ItemsControl)Activator.CreateInstance(defaultComboboxEditor); itemsControl.ItemsSource = standardValues; if (Nullable.GetUnderlyingType(property.ReturnType) != null) { itemsControl.GetType().GetProperty("IsNullable").SetValue(itemsControl, true, null); //In this Class we don't know the Nullable Combo Box } return(itemsControl); } var namedStandardValues = Metadata.GetNamedStandardValues(property.ReturnType); if (namedStandardValues != null) { var itemsControl = (ItemsControl)Activator.CreateInstance(defaultComboboxEditor); itemsControl.ItemsSource = namedStandardValues; itemsControl.DisplayMemberPath = "Name"; ((Selector)itemsControl).SelectedValuePath = "Value"; if (Nullable.GetUnderlyingType(property.ReturnType) != null) { itemsControl.GetType().GetProperty("IsNullable").SetValue(itemsControl, true, null); //In this Class we don't know the Nullable Combo Box } return(itemsControl); } return((FrameworkElement)Activator.CreateInstance(defaultTextboxEditor)); return((FrameworkElement)Activator.CreateInstance(defaultTextboxEditor)); } } return((FrameworkElement)Activator.CreateInstance(editorType)); }
public override void InitializeDefaults(DesignItem item) { DesignItemProperty contentProperty = item.Properties["Content"]; if (contentProperty.ValueOnInstance == null) { contentProperty.SetValue(item.ComponentType.Name); } }
public override void InitializeDefaults(DesignItem item) { DesignItemProperty fillProperty = item.Properties["Fill"]; if (fillProperty.ValueOnInstance == null) { fillProperty.SetValue(Brushes.YellowGreen); } }
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 PasteCustomControlUsingStaticResource() { DesignItem grid = CreateGridContextWithDesignSurface("<Button/>"); DesignItemProperty resProp = grid.Properties.GetProperty("Resources"); Assert.IsTrue(resProp.IsCollection); DesignItem exampleClassItem = grid.Services.Component.RegisterComponentForDesigner(new ExampleClass()); exampleClassItem.Key = "res1"; resProp.CollectionElements.Add(exampleClassItem); DesignItem myButton = grid.Services.Component.RegisterComponentForDesigner(new ICSharpCode.WpfDesign.Tests.Controls.CustomButton()); grid.Properties["Children"].CollectionElements.Add(myButton); myButton.Properties[TextBox.TagProperty].SetValue(new StaticResourceExtension()); myButton.Properties[TextBox.TagProperty].Value.Properties["ResourceKey"].SetValue("res1"); // Verify xaml document to be copied string expectedXaml = "<Grid.Resources>\n" + " <Controls0:ExampleClass x:Key=\"res1\" />\n" + "</Grid.Resources>\n" + "<Button />\n" + "<sdtcontrols:CustomButton Tag=\"{StaticResource ResourceKey=res1}\" />\n"; AssertGridDesignerOutput(expectedXaml, grid.Context, "xmlns:Controls0=\"clr-namespace:ICSharpCode.WpfDesign.Tests.Designer;assembly=ICSharpCode.WpfDesign.Tests\"", "xmlns:sdtcontrols=\"http://sharpdevelop.net/WpfDesign/Tests/Controls\""); var xamlContext = grid.Context as XamlDesignContext; Assert.IsNotNull(xamlContext); xamlContext.XamlEditAction.Copy(new[] { myButton }); grid = CreateGridContextWithDesignSurface("<Button/>"); resProp = grid.Properties.GetProperty("Resources"); Assert.IsTrue(resProp.IsCollection); exampleClassItem = grid.Services.Component.RegisterComponentForDesigner(new ExampleClass()); exampleClassItem.Key = "res1"; resProp.CollectionElements.Add(exampleClassItem); xamlContext = grid.Context as XamlDesignContext; Assert.IsNotNull(xamlContext); var selection = grid.Services.Selection; selection.SetSelectedComponents(new[] { grid }); xamlContext.XamlEditAction.Paste(); AssertGridDesignerOutput(expectedXaml, grid.Context, "xmlns:Controls0=\"clr-namespace:ICSharpCode.WpfDesign.Tests.Designer;assembly=ICSharpCode.WpfDesign.Tests\"", "xmlns:sdtcontrols=\"http://sharpdevelop.net/WpfDesign/Tests/Controls\""); }
public void UndoRedoInputBindings() { const string originalXaml = "<TextBlock Text=\"My text\" />"; DesignItem textBlock = CreateCanvasContext(originalXaml); UndoService s = textBlock.Context.Services.GetService <UndoService>(); IComponentService component = textBlock.Context.Services.Component; Assert.IsFalse(s.CanUndo); Assert.IsFalse(s.CanRedo); DesignItemProperty inputbinding = textBlock.Properties["InputBindings"]; Assert.IsTrue(inputbinding.IsCollection); const string expectedXaml = @"<TextBlock Text=""My text""> <TextBlock.InputBindings> <MouseBinding Gesture=""LeftDoubleClick"" Command=""ApplicationCommands.New"" /> </TextBlock.InputBindings> </TextBlock>"; using (ChangeGroup changeGroup = textBlock.Context.OpenGroup("", new[] { textBlock })) { DesignItem di = component.RegisterComponentForDesigner(new System.Windows.Input.MouseBinding()); di.Properties["Gesture"].SetValue(System.Windows.Input.MouseAction.LeftDoubleClick); di.Properties["Command"].SetValue("ApplicationCommands.New"); inputbinding.CollectionElements.Add(di); changeGroup.Commit(); } Assert.IsTrue(s.CanUndo); Assert.IsFalse(s.CanRedo); AssertCanvasDesignerOutput(expectedXaml, textBlock.Context); inputbinding = textBlock.Properties["InputBindings"]; Assert.IsTrue(((System.Windows.Input.InputBindingCollection)inputbinding.ValueOnInstance).Count == inputbinding.CollectionElements.Count); s.Undo(); Assert.IsFalse(s.CanUndo); Assert.IsTrue(s.CanRedo); AssertCanvasDesignerOutput(originalXaml, textBlock.Context); s.Redo(); Assert.IsTrue(s.CanUndo); Assert.IsFalse(s.CanRedo); AssertCanvasDesignerOutput(expectedXaml, textBlock.Context); Assert.IsTrue(((System.Windows.Input.InputBindingCollection)inputbinding.ValueOnInstance).Count == inputbinding.CollectionElements.Count); AssertLog(""); }
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 LoadItemsCollection(DesignItemProperty itemProperty) { _itemProperty = itemProperty; _componentService=_itemProperty.DesignItem.Services.Component; TypeMappings.TryGetValue(_itemProperty.ReturnType, out _type); _type = _type ?? GetItemsSourceType(_itemProperty.ReturnType); if (_type == null) { AddItem.IsEnabled=false; } ListBox.ItemsSource = _itemProperty.CollectionElements; }
protected override void OnRender(DrawingContext drawingContext) { base.OnRender(drawingContext); if (orientation == Orientation.Horizontal) { Rect bgRect = new Rect(0, 0, grid.ActualWidth, RailSize); drawingContext.DrawRectangle(bgBrush, null, bgRect); DesignItemProperty colCollection = gridItem.Properties["ColumnDefinitions"]; foreach (var colItem in colCollection.CollectionElements) { ColumnDefinition column = colItem.Component as ColumnDefinition; if (column.ActualWidth < 0) { continue; } GridLength len = (GridLength)column.GetValue(ColumnDefinition.WidthProperty); FormattedText text = new FormattedText(GridLengthToText(len), CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Sergio UI"), 10, Brushes.Black); text.TextAlignment = TextAlignment.Center; drawingContext.DrawText(text, new Point(column.Offset + column.ActualWidth / 2, 0)); } } else { Rect bgRect = new Rect(0, 0, RailSize, grid.ActualHeight); drawingContext.DrawRectangle(bgBrush, null, bgRect); DesignItemProperty rowCollection = gridItem.Properties["RowDefinitions"]; foreach (var rowItem in rowCollection.CollectionElements) { RowDefinition row = rowItem.Component as RowDefinition; if (row.ActualHeight < 0) { continue; } GridLength len = (GridLength)row.GetValue(RowDefinition.HeightProperty); FormattedText text = new FormattedText(GridLengthToText(len), CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Sergio UI"), 10, Brushes.Black); text.TextAlignment = TextAlignment.Center; drawingContext.PushTransform(new RotateTransform(-90)); drawingContext.DrawText(text, new Point((row.Offset + row.ActualHeight / 2) * -1, 0)); drawingContext.Pop(); } } }
public void HandleDoubleClick() { if (selectedItems.Count == 1) { IEventHandlerService ehs = clickedOn.Services.GetService <IEventHandlerService>(); if (ehs != null) { DesignItemProperty defaultEvent = ehs.GetDefaultEvent(clickedOn); if (defaultEvent != null) { ehs.CreateEventHandler(defaultEvent); } } } }
public void LoadItemsCollection(DesignItemProperty itemProperty) { _itemProperty = itemProperty; _componentService = _itemProperty.DesignItem.Services.Component; TypeMappings.TryGetValue(_itemProperty.ReturnType, out _type); _type = _type ?? GetItemsSourceType(_itemProperty.ReturnType); if (_type == null) { AddItem.IsEnabled = false; } ListBox.ItemsSource = _itemProperty.CollectionElements; }
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 LoadItemsCollection(DesignItemProperty itemProperty) { _itemProperty = itemProperty; _componentService=_itemProperty.DesignItem.Services.Component; TypeMappings.TryGetValue(_itemProperty.ReturnType, out _type); if (_type == null) { PropertyGridView.IsEnabled=false; ListBox.IsEnabled=false; AddItem.IsEnabled=false; RemoveItem.IsEnabled=false; MoveUpItem.IsEnabled=false; MoveDownItem.IsEnabled=false; } ListBox.ItemsSource = _itemProperty.CollectionElements; }
public void AddBindingWithStaticResourceToMultiBinding() { DesignItem textBox = CreateCanvasContext("<TextBox/>"); DesignItem canvasItem = textBox.Parent; DesignItemProperty canvasResources = canvasItem.Properties.GetProperty("Resources"); DesignItem exampleClassItem = textBox.Services.Component.RegisterComponentForDesigner(new ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClass()); exampleClassItem.Key = "testKey"; exampleClassItem.Properties["StringProp"].SetValue("String value"); canvasResources.CollectionElements.Add(exampleClassItem); DesignItem multiBindingItem = textBox.Context.Services.Component.RegisterComponentForDesigner(new MultiBinding()); multiBindingItem.Properties["Converter"].SetValue(new ReturnFirstValueMultiConverter()); DesignItemProperty bindingsProp = multiBindingItem.ContentProperty; DesignItem myBindingExtension = textBox.Context.Services.Component.RegisterComponentForDesigner(new Binding()); myBindingExtension.Properties["Path"].SetValue("StringProp"); myBindingExtension.Properties["Source"].SetValue(new StaticResourceExtension()); myBindingExtension.Properties["Source"].Value.Properties["ResourceKey"].SetValue("testKey"); // Adding it to MultiBinding "Bindings" collection. bindingsProp.CollectionElements.Add(myBindingExtension); textBox.ContentProperty.SetValue(multiBindingItem); // Verify that the text have the expected value, proving that the StaticResource have been resolved. Assert.AreEqual("String value", ((TextBox)textBox.Component).Text); const string expectedXaml = "<Canvas.Resources>\n" + " <Controls0:ExampleClass x:Key=\"testKey\" StringProp=\"String value\" />\n" + "</Canvas.Resources>\n" + "<TextBox>\n" + " <MultiBinding>\n" + " <MultiBinding.Converter>\n" + " <t:ReturnFirstValueMultiConverter />\n" + " </MultiBinding.Converter>\n" + " <Binding Path=\"StringProp\" Source=\"{StaticResource testKey}\" />\n" + " </MultiBinding>\n" + "</TextBox>"; AssertCanvasDesignerOutput(expectedXaml, textBox.Context, "xmlns:Controls0=\"" + ICSharpCode.WpfDesign.Tests.XamlDom.XamlTypeFinderTests.XamlDomTestsNamespace + "\""); AssertLog(""); }
public void LoadItemsCollection(DesignItemProperty itemProperty) { _itemProperty = itemProperty; _componentService = _itemProperty.DesignItem.Services.Component; TypeMappings.TryGetValue(_itemProperty.ReturnType, out _type); if (_type == null) { PropertyGridView.IsEnabled = false; ListBox.IsEnabled = false; AddItem.IsEnabled = false; RemoveItem.IsEnabled = false; MoveUpItem.IsEnabled = false; MoveDownItem.IsEnabled = false; } ListBox.ItemsSource = _itemProperty.CollectionElements; }
public DesignItemProperty GetDefaultEvent(DesignItem item) { object[] attributes = item.ComponentType.GetCustomAttributes(typeof(DefaultEventAttribute), true); if (attributes.Length == 1) { DefaultEventAttribute dae = (DefaultEventAttribute)attributes[0]; var events = TypeDescriptor.GetEvents(item.Component); var eventInfo = events[dae.Name]; if (eventInfo != null) { DesignItemProperty property = item.Properties.GetProperty(dae.Name); if (property != null && property.IsEvent) { return(property); } } } return(null); }
/// <summary> /// Creates a property editor for the specified <paramref name="property"/> /// </summary> public static FrameworkElement CreateEditor(DesignItemProperty property) { Type editorType; if (!propertyEditors.TryGetValue(property.FullName, out editorType)) { var type = property.ReturnType; while (type != null) { if (typeEditors.TryGetValue(type, out editorType)) { break; } type = type.BaseType; } foreach (var t in typeEditors) { if (t.Key.IsAssignableFrom(property.ReturnType)) { return((FrameworkElement)Activator.CreateInstance(t.Value)); } } if (editorType == null) { var standardValues = Metadata.GetStandardValues(property.ReturnType); if (standardValues != null) { var itemsControl = (ItemsControl)Activator.CreateInstance(defaultComboboxEditor); itemsControl.ItemsSource = standardValues; return(itemsControl); } return((FrameworkElement)Activator.CreateInstance(defaultTextboxEditor)); } } return((FrameworkElement)Activator.CreateInstance(editorType)); }
public object GetDescription(DesignItemProperty property) { IProjectContent pc = MyTypeFinder.GetProjectContent(file); if (pc != null) { // For attached Properties if (property.DependencyFullName != null && property.Name.Contains(".")) { IClass c = pc.GetClassByReflectionName(property.DependencyProperty.OwnerType.FullName, true); if (c != null) { IMember m = DefaultProjectContent.GetMemberByReflectionName(c, property.DependencyProperty.Name + "Property"); if (m != null) return CodeCompletionItem.ConvertDocumentation(m.Documentation); } } else { IClass c = pc.GetClassByReflectionName(property.DeclaringType.FullName, true); if (c != null) { IMember m = DefaultProjectContent.GetMemberByReflectionName(c, property.Name); if (m != null) return CodeCompletionItem.ConvertDocumentation(m.Documentation); } } } return null; }
public void AddMultiBindingToTextBox() { DesignItem button = CreateCanvasContext("<Button/>"); DesignItem canvas = button.Parent; DesignItem textBox = canvas.Services.Component.RegisterComponentForDesigner(new TextBox()); canvas.Properties["Children"].CollectionElements.Add(textBox); textBox.Properties[TextBox.TextProperty].SetValue(new MultiBinding()); DesignItem multiBindingItem = textBox.Properties[TextBox.TextProperty].Value; multiBindingItem.Properties["Converter"].SetValue(new MyMultiConverter()); DesignItemProperty bindingsProp = multiBindingItem.ContentProperty; Assert.IsTrue(bindingsProp.IsCollection); Assert.AreEqual(bindingsProp.Name, "Bindings"); DesignItem bindingItem = canvas.Services.Component.RegisterComponentForDesigner(new Binding()); bindingItem.Properties["Path"].SetValue("SomeProperty"); bindingsProp.CollectionElements.Add(bindingItem); string expectedXaml = "<Button />\n" + "<TextBox>\n" + " <MultiBinding>\n" + " <MultiBinding.Converter>\n" + " <t:MyMultiConverter />\n" + " </MultiBinding.Converter>\n" + " <Binding Path=\"SomeProperty\" />\n" + " </MultiBinding>\n" + "</TextBox>"; AssertCanvasDesignerOutput(expectedXaml, button.Context); AssertLog(""); }
PropertyNode(DesignItemProperty[] properties, PropertyNode parent) : this() { this.Parent = parent; this.Level = parent == null ? 0 : parent.Level + 1; Load(properties); }
/// <summary> /// Initializes this property node with the specified properties. /// </summary> public void Load(DesignItemProperty[] properties) { if (this.Properties != null) { // detach events from old properties foreach (var property in this.Properties) { property.ValueChanged -= new EventHandler(property_ValueChanged); property.ValueOnInstanceChanged -= new EventHandler(property_ValueOnInstanceChanged); } } this.Properties = new ReadOnlyCollection<DesignItemProperty>(properties); if (Editor == null) Editor = EditorManager.CreateEditor(FirstProperty); foreach (var property in properties) { property.ValueChanged += new EventHandler(property_ValueChanged); property.ValueOnInstanceChanged += new EventHandler(property_ValueOnInstanceChanged); } hasStringConverter = FirstProperty.TypeConverter.CanConvertFrom(typeof(string)) && FirstProperty.TypeConverter.CanConvertTo(typeof(string)); OnValueChanged(); }
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); }
/// <summary> /// Creates a new ComponentEventArgs instance. /// </summary> public DesignItemPropertyChangedEventArgs(DesignItem item, DesignItemProperty itemProperty) : base(item) { _itemProperty = itemProperty; }