Browse Source

Merge pull request #593 from jogibear9988/master

Support for {x:Refrence}, Template & Namescope fixes
pull/603/head
Andreas Weizel 12 years ago
parent
commit
a0eafb3922
  1. 1
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ContainerDragHandle.cs
  2. 1
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/PanelMoveAdorner.cs
  3. 1
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/QuickOperationMenu.cs
  4. 11
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/EditStyleContextMenu.xaml
  5. 68
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/EditStyleContextMenu.xaml.cs
  6. 53
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/EditStyleContextMenuExtension.cs
  7. 1
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/SkewThumbExtension.cs
  8. 89
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/SnaplinePlacementBehavior.cs
  9. 1
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TextBlockRightClickContextMenu.xaml.cs
  10. 210
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs
  11. 1
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/OutlineView/OutlineTreeView.cs
  12. 1
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/FormatedTextEditor/FormatedTextEditor.xaml.cs
  13. 1
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ThumbnailView/ThumbnailView.cs
  14. 10
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Translations.cs
  15. 6
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/UIExtensions/UIHelpers.cs
  16. 9
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj
  17. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlComponentService.cs
  18. 5
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlModelCollectionElementsCollection.cs
  19. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/EditOperationTests.cs
  20. 10
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/ModelTests.cs
  21. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/SetPropertyTests.cs
  22. 9
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/WpfDesign.Tests.csproj
  23. 23
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/ExampleControl.cs
  24. 133
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/NamescopeTest.cs
  25. 13
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/NamscopeTestUsercontrol.xaml
  26. 28
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/NamscopeTestUsercontrol.xaml.cs
  27. 159
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/SamplesTests.cs
  28. 77
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/MarkupExtensionPrinter.cs
  29. 28
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/NameScopeHelper.cs
  30. 62
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/TemplateHelper.cs
  31. 1
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/WpfDesign.XamlDom.csproj
  32. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObject.cs
  33. 60
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObjectServiceProvider.cs
  34. 38
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlParser.cs
  35. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs
  36. 5
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlTypeFinder.cs
  37. 3
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlTypeResolverProvider.cs
  38. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementOperation.cs

1
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ContainerDragHandle.cs

@ -27,6 +27,7 @@ using ICSharpCode.WpfDesign.Extensions; @@ -27,6 +27,7 @@ using ICSharpCode.WpfDesign.Extensions;
using ICSharpCode.WpfDesign.Designer.Converters;
using System.Globalization;
using System.Windows.Data;
using ICSharpCode.WpfDesign.Designer.UIExtensions;
namespace ICSharpCode.WpfDesign.Designer.Controls
{

1
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/PanelMoveAdorner.cs

@ -28,6 +28,7 @@ using System.Windows.Media; @@ -28,6 +28,7 @@ using System.Windows.Media;
using ICSharpCode.WpfDesign.Designer.Converters;
using System.Globalization;
using System.Windows.Data;
using ICSharpCode.WpfDesign.Designer.UIExtensions;
namespace ICSharpCode.WpfDesign.Designer.Controls
{

1
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/QuickOperationMenu.cs

@ -25,6 +25,7 @@ using System.Windows.Media; @@ -25,6 +25,7 @@ using System.Windows.Media;
using ICSharpCode.WpfDesign.Designer.Converters;
using System.Globalization;
using System.Windows.Data;
using ICSharpCode.WpfDesign.Designer.UIExtensions;
namespace ICSharpCode.WpfDesign.Designer.Controls

11
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/EditStyleContextMenu.xaml

@ -0,0 +1,11 @@ @@ -0,0 +1,11 @@
<ContextMenu x:Class="ICSharpCode.WpfDesign.Designer.Extensions.EditStyleContextMenu"
xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Translation="clr-namespace:ICSharpCode.WpfDesign.Designer"
>
<MenuItem Header="{Binding EditStyle, Source={x:Static Translation:Translations.Instance}}" Click="Click_EditStyle">
<MenuItem.Icon>
<Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/edit.png" />
</MenuItem.Icon>
</MenuItem>
</ContextMenu>

68
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/EditStyleContextMenu.xaml.cs

@ -0,0 +1,68 @@ @@ -0,0 +1,68 @@
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;
using System.Xml;
using ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.FormatedTextEditor;
using ICSharpCode.WpfDesign.Designer.Xaml;
using ICSharpCode.WpfDesign.XamlDom;
namespace ICSharpCode.WpfDesign.Designer.Extensions
{
public partial class EditStyleContextMenu
{
private DesignItem designItem;
public EditStyleContextMenu(DesignItem designItem)
{
this.designItem = designItem;
InitializeComponent();
}
void Click_EditStyle(object sender, RoutedEventArgs e)
{
var element = designItem.View;
object defaultStyleKey = element.GetValue(FrameworkElement.DefaultStyleKeyProperty);
Style style = Application.Current.TryFindResource(defaultStyleKey) as Style;
var service = ((XamlComponentService) designItem.Services.Component);
var ms = new MemoryStream();
XmlTextWriter writer = new XmlTextWriter(ms, System.Text.Encoding.UTF8);
writer.Formatting = Formatting.Indented;
XamlWriter.Save(style, writer);
var rootItem = this.designItem.Context.RootItem as XamlDesignItem;
ms.Position = 0;
var sr = new StreamReader(ms);
var xaml = sr.ReadToEnd();
var xamlObject = XamlParser.ParseSnippet(rootItem.XamlObject, xaml, ((XamlDesignContext)this.designItem.Context).ParserSettings);
var styleDesignItem=service.RegisterXamlComponentRecursive(xamlObject);
designItem.Properties.GetProperty("Resources").CollectionElements.Add(styleDesignItem);
}
}
}

53
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/EditStyleContextMenuExtension.cs

@ -0,0 +1,53 @@ @@ -0,0 +1,53 @@
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Linq;
using System.Windows.Controls;
using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Extensions;
namespace ICSharpCode.WpfDesign.Designer.Extensions
{
[ExtensionServer(typeof (OnlyOneItemSelectedExtensionServer))]
[ExtensionFor(typeof (Control))]
[Extension(Order = 10)]
public class EditStyleContextMenuExtension : PrimarySelectionAdornerProvider
{
DesignPanel panel;
ContextMenu contextMenu;
protected override void OnInitialized()
{
base.OnInitialized();
contextMenu = new EditStyleContextMenu(ExtendedItem);
panel = ExtendedItem.Context.Services.DesignPanel as DesignPanel;
if (panel != null)
panel.AddContextMenu(contextMenu);
}
protected override void OnRemove()
{
if (panel != null)
panel.RemoveContextMenu(contextMenu);
base.OnRemove();
}
}
}

1
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/SkewThumbExtension.cs

@ -27,6 +27,7 @@ using ICSharpCode.WpfDesign.Adorners; @@ -27,6 +27,7 @@ using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Designer.Controls;
using ICSharpCode.WpfDesign.Extensions;
using System.Collections.Generic;
using ICSharpCode.WpfDesign.Designer.UIExtensions;
namespace ICSharpCode.WpfDesign.Designer.Extensions
{

89
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/SnaplinePlacementBehavior.cs

@ -19,16 +19,11 @@ @@ -19,16 +19,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using ICSharpCode.WpfDesign.Extensions;
using System.ComponentModel;
using ICSharpCode.WpfDesign.Adorners;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
using System.Windows.Automation.Peers;
using System.Windows.Controls.Primitives;
using System.Diagnostics;
using System.Windows.Input;
@ -36,6 +31,20 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -36,6 +31,20 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
{
public class SnaplinePlacementBehavior : RasterPlacementBehavior
{
public static bool GetDisableSnaplines(DependencyObject obj)
{
return (bool)obj.GetValue(DisableSnaplinesProperty);
}
public static void SetDisableSnaplines(DependencyObject obj, bool value)
{
obj.SetValue(DisableSnaplinesProperty, value);
}
public static readonly DependencyProperty DisableSnaplinesProperty =
DependencyProperty.RegisterAttached("DisableSnaplines", typeof(bool), typeof(SnaplinePlacementBehavior), new PropertyMetadata(false));
AdornerPanel adornerPanel;
Canvas surface;
List<Snapline> horizontalMap;
@ -194,16 +203,16 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -194,16 +203,16 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
if (designItem != null && designItem.ContentProperty != null && designItem.ContentProperty.IsCollection)
foreach (var collectionElement in designItem.ContentProperty.CollectionElements)
{
if (collectionElement != null)
yield return collectionElement;
{
if (collectionElement != null)
yield return collectionElement;
foreach (var el in AllDesignItems(collectionElement))
{
if (el != null)
yield return el;
}
foreach (var el in AllDesignItems(collectionElement))
{
if (el != null)
yield return el;
}
}
}
void BuildMaps(PlacementOperation operation)
@ -217,7 +226,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -217,7 +226,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
AddLines(containerRect, 0, false);
foreach (var item in AllDesignItems() /* ExtendedItem.ContentProperty.CollectionElements */
.Except(operation.PlacedItems.Select(f => f.Item))) {
.Except(operation.PlacedItems.Select(f => f.Item))
.Where(x=>!GetDisableSnaplines(x.View))) {
if (item != null) {
var bounds = GetPosition(operation, item);
@ -235,26 +245,26 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -235,26 +245,26 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
void AddLines(Rect r, double inflate, bool requireOverlap, List<Snapline> h, List<Snapline> v, PlacementAlignment? filter)
{
if (r != Rect.Empty)
{
Rect r2 = r;
r2.Inflate(inflate, inflate);
if (filter == null || filter.Value.Vertical == VerticalAlignment.Top)
h.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Top - 1, Start = r.Left, End = r.Right });
if (filter == null || filter.Value.Vertical == VerticalAlignment.Bottom)
h.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Bottom - 1, Start = r.Left, End = r.Right });
if (filter == null || filter.Value.Horizontal == HorizontalAlignment.Left)
v.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Left - 1, Start = r.Top, End = r.Bottom });
if (filter == null || filter.Value.Horizontal == HorizontalAlignment.Right)
v.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Right - 1, Start = r.Top, End = r.Bottom });
if (filter == null)
{
h.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Top + Math.Abs((r2.Top - r2.Bottom) / 2), Start = r.Left, End = r.Right });
v.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Left + Math.Abs((r2.Left - r2.Right) / 2), Start = r.Top, End = r.Bottom });
}
}
if (r != Rect.Empty)
{
Rect r2 = r;
r2.Inflate(inflate, inflate);
if (filter == null || filter.Value.Vertical == VerticalAlignment.Top)
h.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Top - 1, Start = r.Left, End = r.Right });
if (filter == null || filter.Value.Vertical == VerticalAlignment.Bottom)
h.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Bottom - 1, Start = r.Left, End = r.Right });
if (filter == null || filter.Value.Horizontal == HorizontalAlignment.Left)
v.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Left - 1, Start = r.Top, End = r.Bottom });
if (filter == null || filter.Value.Horizontal == HorizontalAlignment.Right)
v.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Right - 1, Start = r.Top, End = r.Bottom });
if (filter == null)
{
h.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Top + Math.Abs((r2.Top - r2.Bottom) / 2), Start = r.Left, End = r.Right });
v.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Left + Math.Abs((r2.Left - r2.Right) / 2), Start = r.Top, End = r.Bottom });
}
}
}
void AddBaseline(DesignItem item, Rect bounds, List<Snapline> list)
@ -279,9 +289,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -279,9 +289,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
void DrawLine(double x1, double y1, double x2, double y2)
{
if (double.IsInfinity(x1) || double.IsNaN(x1) || double.IsInfinity(y1) || double.IsNaN(y1) ||
double.IsInfinity(x2) || double.IsNaN(x2) || double.IsInfinity(y2) || double.IsNaN(y2))
return;
if (double.IsInfinity(x1) || double.IsNaN(x1) || double.IsInfinity(y1) || double.IsNaN(y1) ||
double.IsInfinity(x2) || double.IsNaN(x2) || double.IsInfinity(y2) || double.IsNaN(y2))
return;
var line1 = new Line() {
X1 = x1,
@ -321,7 +331,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -321,7 +331,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
}
static bool Snap(List<Snapline> input, List<Snapline> map, double accuracy,
out List<Snapline> drawLines, out double delta)
out List<Snapline> drawLines, out double delta)
{
delta = double.MaxValue;
drawLines = null;
@ -330,7 +340,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -330,7 +340,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
foreach (var mapLine in map) {
if (Math.Abs(mapLine.Offset - inputLine.Offset) <= accuracy) {
if (!inputLine.RequireOverlap && !mapLine.RequireOverlap ||
Math.Max(inputLine.Start, mapLine.Start) < Math.Min(inputLine.End, mapLine.End))
Math.Max(inputLine.Start, mapLine.Start) < Math.Min(inputLine.End, mapLine.End))
{
if (mapLine.Group == inputLine.Group)
delta = mapLine.Offset - inputLine.Offset;
@ -376,4 +386,3 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -376,4 +386,3 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
}
}
}

1
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TextBlockRightClickContextMenu.xaml.cs

@ -20,6 +20,7 @@ using System; @@ -20,6 +20,7 @@ using System;
using System.Linq;
using System.Windows;
using ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.FormatedTextEditor;
using ICSharpCode.WpfDesign.Designer.UIExtensions;
namespace ICSharpCode.WpfDesign.Designer.Extensions
{

210
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs

@ -119,7 +119,7 @@ namespace ICSharpCode.WpfDesign.Designer @@ -119,7 +119,7 @@ namespace ICSharpCode.WpfDesign.Designer
}
}
internal static void CreateVisualTree(this UIElement element)
public static void CreateVisualTree(this UIElement element)
{
try
{
@ -227,7 +227,7 @@ namespace ICSharpCode.WpfDesign.Designer @@ -227,7 +227,7 @@ namespace ICSharpCode.WpfDesign.Designer
{
var itemPos = new ItemPos() {DesignItem = designItem};
var pos = operation.CurrentContainerBehavior.GetPosition(operation, designItem);
var pos = operation.CurrentContainerBehavior.GetPosition(operation, designItem);
itemPos.Xmin = pos.X;
itemPos.Xmax = pos.X + pos.Width;
itemPos.Ymin = pos.Y;
@ -252,7 +252,7 @@ namespace ICSharpCode.WpfDesign.Designer @@ -252,7 +252,7 @@ namespace ICSharpCode.WpfDesign.Designer
if (placement == null)
return;
var operation = PlacementOperation.Start(items.ToList(), PlacementType.Move);
var operation = PlacementOperation.Start(items.ToList(), PlacementType.Move);
var newInstance = Activator.CreateInstance(containerType);
DesignItem newPanel = _context.Services.Component.RegisterComponentForDesigner(newInstance);
@ -261,7 +261,7 @@ namespace ICSharpCode.WpfDesign.Designer @@ -261,7 +261,7 @@ namespace ICSharpCode.WpfDesign.Designer
List<ItemPos> itemList = new List<ItemPos>();
foreach (var item in collection) {
itemList.Add(GetItemPos(operation, item));
itemList.Add(GetItemPos(operation, item));
//var pos = placement.GetPosition(null, item);
if (container.Component is Canvas) {
item.Properties.GetAttachedProperty(Canvas.RightProperty).Reset();
@ -297,7 +297,7 @@ namespace ICSharpCode.WpfDesign.Designer @@ -297,7 +297,7 @@ namespace ICSharpCode.WpfDesign.Designer
item.DesignItem.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(item.Ymin - ymin);
}
newPanel.ContentProperty.CollectionElements.Add(item.DesignItem);
newPanel.ContentProperty.CollectionElements.Add(item.DesignItem);
} else if (newPanel.Component is Grid) {
Thickness thickness = new Thickness(0);
@ -319,21 +319,21 @@ namespace ICSharpCode.WpfDesign.Designer @@ -319,21 +319,21 @@ namespace ICSharpCode.WpfDesign.Designer
item.DesignItem.Properties.GetProperty(FrameworkElement.MarginProperty).SetValue(thickness);
newPanel.ContentProperty.CollectionElements.Add(item.DesignItem);
newPanel.ContentProperty.CollectionElements.Add(item.DesignItem);
} else if (newPanel.Component is Viewbox) {
newPanel.ContentProperty.SetValue(item.DesignItem);
newPanel.ContentProperty.SetValue(item.DesignItem);
}
}
PlacementOperation operation2 = PlacementOperation.TryStartInsertNewComponents(
PlacementOperation operation2 = PlacementOperation.TryStartInsertNewComponents(
container,
new[] { newPanel },
new[] { new Rect(xmin, ymin, xmax - xmin, ymax - ymin).Round() },
PlacementType.AddItem
);
operation2.Commit();
operation2.Commit();
operation.Commit();
@ -355,7 +355,7 @@ namespace ICSharpCode.WpfDesign.Designer @@ -355,7 +355,7 @@ namespace ICSharpCode.WpfDesign.Designer
if (placement == null)
return;
var operation = PlacementOperation.Start(items.ToList(), PlacementType.Move);
var operation = PlacementOperation.Start(items.ToList(), PlacementType.Move);
//var changeGroup = container.OpenGroup("Arrange Elements");
@ -392,19 +392,19 @@ namespace ICSharpCode.WpfDesign.Designer @@ -392,19 +392,19 @@ namespace ICSharpCode.WpfDesign.Designer
}
else if (container.Component is Grid)
{
if ((HorizontalAlignment)item.Properties.GetProperty(FrameworkElement.HorizontalAlignmentProperty).ValueOnInstance != HorizontalAlignment.Right)
{
var margin = (Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance;
margin.Left = xmin;
item.Properties.GetProperty(FrameworkElement.MarginProperty).SetValue(margin);
}
else
{
var pos = (double)((Panel)item.Parent.Component).ActualWidth - (xmin + (double)((FrameworkElement)item.Component).ActualWidth);
var margin = (Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance;
margin.Right = pos;
item.Properties.GetProperty(FrameworkElement.MarginProperty).SetValue(margin);
}
if ((HorizontalAlignment)item.Properties.GetProperty(FrameworkElement.HorizontalAlignmentProperty).ValueOnInstance != HorizontalAlignment.Right)
{
var margin = (Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance;
margin.Left = xmin;
item.Properties.GetProperty(FrameworkElement.MarginProperty).SetValue(margin);
}
else
{
var pos = (double)((Panel)item.Parent.Component).ActualWidth - (xmin + (double)((FrameworkElement)item.Component).ActualWidth);
var margin = (Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance;
margin.Right = pos;
item.Properties.GetProperty(FrameworkElement.MarginProperty).SetValue(margin);
}
}
}
break;
@ -414,34 +414,34 @@ namespace ICSharpCode.WpfDesign.Designer @@ -414,34 +414,34 @@ namespace ICSharpCode.WpfDesign.Designer
{
if (!item.Properties.GetAttachedProperty(Canvas.RightProperty).IsSet)
{
if (!item.Properties.GetAttachedProperty(Canvas.RightProperty).IsSet)
{
item.Properties.GetAttachedProperty(Canvas.LeftProperty).SetValue(mpos - (((FrameworkElement)item.Component).ActualWidth) / 2);
}
else
{
var pp = mpos - (((FrameworkElement)item.Component).ActualWidth) / 2;
var pos = (double)((Panel)item.Parent.Component).ActualWidth - pp - (((FrameworkElement)item.Component).ActualWidth);
item.Properties.GetAttachedProperty(Canvas.RightProperty).SetValue(pos);
}
}
if (!item.Properties.GetAttachedProperty(Canvas.RightProperty).IsSet)
{
item.Properties.GetAttachedProperty(Canvas.LeftProperty).SetValue(mpos - (((FrameworkElement)item.Component).ActualWidth) / 2);
}
else
{
var pp = mpos - (((FrameworkElement)item.Component).ActualWidth) / 2;
var pos = (double)((Panel)item.Parent.Component).ActualWidth - pp - (((FrameworkElement)item.Component).ActualWidth);
item.Properties.GetAttachedProperty(Canvas.RightProperty).SetValue(pos);
}
}
}
else if (container.Component is Grid)
{
if ((HorizontalAlignment)item.Properties.GetProperty(FrameworkElement.HorizontalAlignmentProperty).ValueOnInstance != HorizontalAlignment.Right)
{
var margin = (Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance;
margin.Left = mpos - (((FrameworkElement)item.Component).ActualWidth) / 2;
item.Properties.GetProperty(FrameworkElement.MarginProperty).SetValue(margin);
}
else
{
var pp = mpos - (((FrameworkElement)item.Component).ActualWidth) / 2;
var pos = (double)((Panel)item.Parent.Component).ActualWidth - pp - (((FrameworkElement)item.Component).ActualWidth);
var margin = (Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance;
margin.Right = pos;
item.Properties.GetProperty(FrameworkElement.MarginProperty).SetValue(margin);
}
if ((HorizontalAlignment)item.Properties.GetProperty(FrameworkElement.HorizontalAlignmentProperty).ValueOnInstance != HorizontalAlignment.Right)
{
var margin = (Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance;
margin.Left = mpos - (((FrameworkElement)item.Component).ActualWidth) / 2;
item.Properties.GetProperty(FrameworkElement.MarginProperty).SetValue(margin);
}
else
{
var pp = mpos - (((FrameworkElement)item.Component).ActualWidth) / 2;
var pos = (double)((Panel)item.Parent.Component).ActualWidth - pp - (((FrameworkElement)item.Component).ActualWidth);
var margin = (Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance;
margin.Right = pos;
item.Properties.GetProperty(FrameworkElement.MarginProperty).SetValue(margin);
}
}
}
break;
@ -462,20 +462,20 @@ namespace ICSharpCode.WpfDesign.Designer @@ -462,20 +462,20 @@ namespace ICSharpCode.WpfDesign.Designer
}
else if (container.Component is Grid)
{
if ((HorizontalAlignment)item.Properties.GetProperty(FrameworkElement.HorizontalAlignmentProperty).ValueOnInstance != HorizontalAlignment.Right)
{
var pos = xmax - (double)((FrameworkElement)item.Component).ActualWidth;
var margin = (Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance;
margin.Left = pos;
item.Properties.GetProperty(FrameworkElement.MarginProperty).SetValue(margin);
}
else
{
var pos = (double)((Panel)item.Parent.Component).ActualWidth - xmax;
var margin = (Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance;
margin.Right = pos;
item.Properties.GetProperty(FrameworkElement.MarginProperty).SetValue(margin);
}
if ((HorizontalAlignment)item.Properties.GetProperty(FrameworkElement.HorizontalAlignmentProperty).ValueOnInstance != HorizontalAlignment.Right)
{
var pos = xmax - (double)((FrameworkElement)item.Component).ActualWidth;
var margin = (Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance;
margin.Left = pos;
item.Properties.GetProperty(FrameworkElement.MarginProperty).SetValue(margin);
}
else
{
var pos = (double)((Panel)item.Parent.Component).ActualWidth - xmax;
var margin = (Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance;
margin.Right = pos;
item.Properties.GetProperty(FrameworkElement.MarginProperty).SetValue(margin);
}
}
}
break;
@ -495,20 +495,20 @@ namespace ICSharpCode.WpfDesign.Designer @@ -495,20 +495,20 @@ namespace ICSharpCode.WpfDesign.Designer
}
else if (container.Component is Grid)
{
if ((VerticalAlignment)item.Properties.GetProperty(FrameworkElement.VerticalAlignmentProperty).ValueOnInstance != VerticalAlignment.Bottom)
{
item.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(ymin);
var margin = (Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance;
margin.Top = ymin;
item.Properties.GetProperty(FrameworkElement.MarginProperty).SetValue(margin);
}
else
{
var pos = (double)((Panel)item.Parent.Component).ActualHeight - (ymin + (double)((FrameworkElement)item.Component).ActualHeight);
var margin = (Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance;
margin.Bottom = pos;
item.Properties.GetProperty(FrameworkElement.MarginProperty).SetValue(margin);
}
if ((VerticalAlignment)item.Properties.GetProperty(FrameworkElement.VerticalAlignmentProperty).ValueOnInstance != VerticalAlignment.Bottom)
{
item.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(ymin);
var margin = (Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance;
margin.Top = ymin;
item.Properties.GetProperty(FrameworkElement.MarginProperty).SetValue(margin);
}
else
{
var pos = (double)((Panel)item.Parent.Component).ActualHeight - (ymin + (double)((FrameworkElement)item.Component).ActualHeight);
var margin = (Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance;
margin.Bottom = pos;
item.Properties.GetProperty(FrameworkElement.MarginProperty).SetValue(margin);
}
}
}
break;
@ -529,20 +529,20 @@ namespace ICSharpCode.WpfDesign.Designer @@ -529,20 +529,20 @@ namespace ICSharpCode.WpfDesign.Designer
}
else if (container.Component is Grid)
{
if ((VerticalAlignment)item.Properties.GetProperty(FrameworkElement.VerticalAlignmentProperty).ValueOnInstance != VerticalAlignment.Bottom)
{
var margin = (Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance;
margin.Top = ympos - (((FrameworkElement)item.Component).ActualHeight) / 2;
item.Properties.GetProperty(FrameworkElement.MarginProperty).SetValue(margin);
}
else
{
var pp = mpos - (((FrameworkElement)item.Component).ActualHeight) / 2;
var pos = (double)((Panel)item.Parent.Component).ActualHeight - pp - (((FrameworkElement)item.Component).ActualHeight);
var margin = (Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance;
margin.Bottom = pos;
item.Properties.GetProperty(FrameworkElement.MarginProperty).SetValue(margin);
}
if ((VerticalAlignment)item.Properties.GetProperty(FrameworkElement.VerticalAlignmentProperty).ValueOnInstance != VerticalAlignment.Bottom)
{
var margin = (Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance;
margin.Top = ympos - (((FrameworkElement)item.Component).ActualHeight) / 2;
item.Properties.GetProperty(FrameworkElement.MarginProperty).SetValue(margin);
}
else
{
var pp = mpos - (((FrameworkElement)item.Component).ActualHeight) / 2;
var pos = (double)((Panel)item.Parent.Component).ActualHeight - pp - (((FrameworkElement)item.Component).ActualHeight);
var margin = (Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance;
margin.Bottom = pos;
item.Properties.GetProperty(FrameworkElement.MarginProperty).SetValue(margin);
}
}
}
break;
@ -563,27 +563,27 @@ namespace ICSharpCode.WpfDesign.Designer @@ -563,27 +563,27 @@ namespace ICSharpCode.WpfDesign.Designer
}
else if (container.Component is Grid)
{
if ((VerticalAlignment)item.Properties.GetProperty(FrameworkElement.VerticalAlignmentProperty).ValueOnInstance != VerticalAlignment.Bottom)
{
var pos = ymax - (double)((FrameworkElement)item.Component).ActualHeight;
var margin = (Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance;
margin.Top = pos;
item.Properties.GetProperty(FrameworkElement.MarginProperty).SetValue(margin);
}
else
{
var pos = (double)((Panel)item.Parent.Component).ActualHeight - ymax;
var margin = (Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance;
margin.Bottom = pos;
item.Properties.GetProperty(FrameworkElement.MarginProperty).SetValue(margin);
}
if ((VerticalAlignment)item.Properties.GetProperty(FrameworkElement.VerticalAlignmentProperty).ValueOnInstance != VerticalAlignment.Bottom)
{
var pos = ymax - (double)((FrameworkElement)item.Component).ActualHeight;
var margin = (Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance;
margin.Top = pos;
item.Properties.GetProperty(FrameworkElement.MarginProperty).SetValue(margin);
}
else
{
var pos = (double)((Panel)item.Parent.Component).ActualHeight - ymax;
var margin = (Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance;
margin.Bottom = pos;
item.Properties.GetProperty(FrameworkElement.MarginProperty).SetValue(margin);
}
}
}
break;
}
}
operation.Commit();
operation.Commit();
}
}
}

1
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/OutlineView/OutlineTreeView.cs

@ -20,6 +20,7 @@ using System; @@ -20,6 +20,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ICSharpCode.WpfDesign.Designer.UIExtensions;
namespace ICSharpCode.WpfDesign.Designer.OutlineView
{

1
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/FormatedTextEditor/FormatedTextEditor.xaml.cs

@ -23,6 +23,7 @@ using System.Windows.Controls; @@ -23,6 +23,7 @@ using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Media;
using ICSharpCode.WpfDesign.Designer.Xaml;
using ICSharpCode.WpfDesign.Designer.UIExtensions;
namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.FormatedTextEditor
{

1
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ThumbnailView/ThumbnailView.cs

@ -27,6 +27,7 @@ using System.Windows.Controls.Primitives; @@ -27,6 +27,7 @@ using System.Windows.Controls.Primitives;
using System.Windows.Media;
using System.Diagnostics;
using ICSharpCode.WpfDesign.Designer.Controls;
using ICSharpCode.WpfDesign.Designer.UIExtensions;
namespace ICSharpCode.WpfDesign.Designer.ThumbnailView
{

10
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Translations.cs

@ -84,7 +84,7 @@ namespace ICSharpCode.WpfDesign.Designer @@ -84,7 +84,7 @@ namespace ICSharpCode.WpfDesign.Designer
}
}
public virtual string WrapInViewbox {
public virtual string WrapInViewbox {
get {
return "Wrap in Viewbox";
}
@ -145,5 +145,13 @@ namespace ICSharpCode.WpfDesign.Designer @@ -145,5 +145,13 @@ namespace ICSharpCode.WpfDesign.Designer
return "Arrange Bottom";
}
}
public virtual string EditStyle
{
get
{
return "Edit Style";
}
}
}
}

6
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/UIHelpers.cs → src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/UIExtensions/UIHelpers.cs

@ -23,9 +23,9 @@ using System.Text; @@ -23,9 +23,9 @@ using System.Text;
using System.Windows;
using System.Windows.Media;
namespace ICSharpCode.WpfDesign.Designer
namespace ICSharpCode.WpfDesign.Designer.UIExtensions
{
static class UIHelpers
public static class UIHelpers
{
public static DependencyObject GetParentObject(this DependencyObject child)
{
@ -85,7 +85,7 @@ namespace ICSharpCode.WpfDesign.Designer @@ -85,7 +85,7 @@ namespace ICSharpCode.WpfDesign.Designer
return null;
}
public static T TryFindChild<T>(DependencyObject parent, string childName) where T : DependencyObject
public static T TryFindChild<T>(this DependencyObject parent, string childName) where T : DependencyObject
{
if (parent == null) return null;
T foundChild = null;

9
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj

@ -87,6 +87,9 @@ @@ -87,6 +87,9 @@
<Compile Include="Controls\RenderTransformOriginThumb.cs" />
<Compile Include="Extensions\BorderForImageControl.cs" />
<Compile Include="Extensions\PartialPanelSelectionHandler.cs" />
<Compile Include="Extensions\EditStyleContextMenu.xaml.cs">
<DependentUpon>EditStyleContextMenu.xaml</DependentUpon>
</Compile>
<Compile Include="Extensions\TextBlockRightClickContextMenu.xaml.cs">
<DependentUpon>TextBlockRightClickContextMenu.xaml</DependentUpon>
</Compile>
@ -96,6 +99,7 @@ @@ -96,6 +99,7 @@
</Compile>
<Compile Include="Extensions\RenderTransformOriginExtension.cs" />
<Compile Include="Extensions\RightClickContextMenuExtension.cs" />
<Compile Include="Extensions\EditStyleContextMenuExtension.cs" />
<Compile Include="Extensions\TextBlockRightClickContextMenuExtension.cs" />
<Compile Include="Extensions\ArrangeItemsContextMenuExtension.cs" />
<Compile Include="Extensions\ArrangeItemsContextMenu.xaml.cs">
@ -273,7 +277,7 @@ @@ -273,7 +277,7 @@
<Compile Include="Services\XamlErrorService.cs" />
<Compile Include="SharedInstances.cs" />
<Compile Include="ThumbnailView\ThumbnailView.cs" />
<Compile Include="UIHelpers.cs" />
<Compile Include="UIExtensions\UIHelpers.cs" />
<Compile Include="Xaml\XamlEditOperations.cs" />
<Compile Include="Xaml\XamlLoadSettings.cs" />
<Compile Include="Xaml\XamlModelCollectionElementsCollection.cs" />
@ -285,6 +289,9 @@ @@ -285,6 +289,9 @@
<Resource Include="Images\Tag.png" />
</ItemGroup>
<ItemGroup>
<Page Include="Extensions\EditStyleContextMenu.xaml">
<SubType>Designer</SubType>
</Page>
<Page Include="Extensions\TextBlockRightClickContextMenu.xaml">
<SubType>Designer</SubType>
</Page>

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlComponentService.cs

@ -105,7 +105,7 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -105,7 +105,7 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
}
if (_context.RootItem != null && !string.IsNullOrEmpty(site.Name)) {
var nameScope = NameScopeHelper.GetNameScopeFromObject(_context.RootItem.Component);
var nameScope = NameScopeHelper.GetNameScopeFromObject(((XamlDesignItem)_context.RootItem).XamlObject);
if (nameScope != null) {
// The object will be a part of the RootItem namescope, remove local namescope if set

5
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlModelCollectionElementsCollection.cs

@ -20,6 +20,7 @@ using System; @@ -20,6 +20,7 @@ using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows;
using ICSharpCode.WpfDesign.XamlDom;
using ICSharpCode.WpfDesign.Designer.Services;
using System.Collections.Specialized;
@ -174,6 +175,8 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -174,6 +175,8 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
void RemoveInternal(int index, XamlDesignItem item)
{
NameScopeHelper.NameChanged(item.XamlObject, item.Name, null);
Debug.Assert(property.CollectionElements[index] == item.XamlObject);
property.CollectionElements.RemoveAt(index);
@ -187,6 +190,8 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -187,6 +190,8 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
if (CollectionChanged != null)
CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, index));
NameScopeHelper.NameChanged(item.XamlObject, null, item.Name);
}
sealed class InsertAction : ITransactionItem

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/EditOperationTests.cs

@ -291,7 +291,7 @@ namespace ICSharpCode.WpfDesign.Tests.Designer @@ -291,7 +291,7 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
" <Controls0:ExampleClass x:Key=\"res1\" />\n" +
"</Grid.Resources>\n" +
"<Button />\n" +
"<sdtcontrols:CustomButton Tag=\"{StaticResource ResourceKey=res1}\" />\n";
"<sdtcontrols:CustomButton Tag=\"{StaticResource res1}\" />\n";
AssertGridDesignerOutput(expectedXaml, grid.Context,
"xmlns:Controls0=\"clr-namespace:ICSharpCode.WpfDesign.Tests.Designer;assembly=ICSharpCode.WpfDesign.Tests\"",

10
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/ModelTests.cs

@ -553,7 +553,7 @@ namespace ICSharpCode.WpfDesign.Tests.Designer @@ -553,7 +553,7 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
textBox.Properties[TextBox.TextProperty].Value.Properties["Path"].SetValue("SomeProperty");
string expectedXaml = "<Button />\n" +
"<TextBox Text=\"{Binding Path=SomeProperty}\" />\n";
"<TextBox Text=\"{Binding SomeProperty}\" />\n";
AssertCanvasDesignerOutput(expectedXaml, button.Context);
AssertLog("");
@ -583,7 +583,7 @@ namespace ICSharpCode.WpfDesign.Tests.Designer @@ -583,7 +583,7 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
" <t:ExampleClass x:Key=\"bindingSource\" />\n" +
"</Canvas.Resources>\n" +
"<Button />\n" +
"<TextBox Text=\"{Binding Path=StringProp, Source={StaticResource ResourceKey=bindingSource}}\" />";
"<TextBox Text=\"{Binding StringProp, Source={StaticResource bindingSource}}\" />";
AssertCanvasDesignerOutput(expectedXaml, button.Context);
AssertLog("");
@ -620,7 +620,7 @@ namespace ICSharpCode.WpfDesign.Tests.Designer @@ -620,7 +620,7 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
" <TextBox.Resources>\n" +
" <t:ExampleClass x:Key=\"bindingSource\" />\n" +
" </TextBox.Resources>\n" +
" <Binding Path=\"StringProp\" Source=\"{StaticResource ResourceKey=bindingSource}\" />\n" +
" <Binding Path=\"StringProp\" Source=\"{StaticResource bindingSource}\" />\n" +
"</TextBox>";
AssertCanvasDesignerOutput(expectedXaml, button.Context);
@ -689,7 +689,7 @@ namespace ICSharpCode.WpfDesign.Tests.Designer @@ -689,7 +689,7 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
string expectedXaml = "<Canvas.Resources>\n" +
" <SolidColorBrush x:Key=\"testBrush\" Color=\"#FFFF00FF\" />\n" +
"</Canvas.Resources>\n" +
"<CheckBox Foreground=\"{StaticResource ResourceKey=testBrush}\" />";
"<CheckBox Foreground=\"{StaticResource testBrush}\" />";
AssertCanvasDesignerOutput(expectedXaml, checkBox.Context);
AssertLog("");
@ -722,7 +722,7 @@ namespace ICSharpCode.WpfDesign.Tests.Designer @@ -722,7 +722,7 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
string expectedXaml = "<Canvas.Resources>\n" +
" <" + typePrefix + typeName + " x:Key=\"res1\">" + expectedXamlValue + "</" + typePrefix + typeName + ">\n" +
"</Canvas.Resources>\n" +
"<TextBlock Tag=\"{StaticResource ResourceKey=res1}\" />";
"<TextBlock Tag=\"{StaticResource res1}\" />";
AssertCanvasDesignerOutput(expectedXaml, textBlock.Context, additionalXmlns);
AssertLog("");

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/SetPropertyTests.cs

@ -44,7 +44,7 @@ namespace ICSharpCode.WpfDesign.Tests.Designer @@ -44,7 +44,7 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
button.Properties.GetProperty("Content").SetValue(new StaticResourceExtension());
button.Properties.GetProperty("Content").Value.Properties["ResourceKey"].SetValue("MyBrush");
// TODO : maybe we should support positional arguments from ctors as well => {StaticResource MyBrush}?
AssertCanvasDesignerOutput("<Button Width=\"100\" Height=\"200\" Content=\"{StaticResource ResourceKey=MyBrush}\" />", button.Context);
AssertCanvasDesignerOutput("<Button Width=\"100\" Height=\"200\" Content=\"{StaticResource MyBrush}\" />", button.Context);
}
[Test]

9
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/WpfDesign.Tests.csproj

@ -75,8 +75,13 @@ @@ -75,8 +75,13 @@
<Compile Include="XamlDom\CollectionTests.cs" />
<Compile Include="XamlDom\ExampleClass.cs" />
<Compile Include="XamlDom\ExampleClassContainer.cs" />
<Compile Include="XamlDom\ExampleControl.cs" />
<Compile Include="XamlDom\ExampleService.cs" />
<Compile Include="XamlDom\MarkupExtensionTests.cs" />
<Compile Include="XamlDom\NamescopeTest.cs" />
<Compile Include="XamlDom\NamscopeTestUsercontrol.xaml.cs">
<DependentUpon>NamscopeTestUsercontrol.xaml</DependentUpon>
</Compile>
<Compile Include="XamlDom\SamplesTests.cs" />
<Compile Include="XamlDom\SimpleLoadTests.cs" />
<Compile Include="XamlDom\SystemTypesLoadTest.cs" />
@ -106,5 +111,9 @@ @@ -106,5 +111,9 @@
<Page Include="Test.xaml">
<SubType>Designer</SubType>
</Page>
<Page Include="XamlDom\NamscopeTestUsercontrol.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
</Project>

23
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/ExampleControl.cs

@ -0,0 +1,23 @@ @@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
namespace ICSharpCode.WpfDesign.Tests.XamlDom
{
public class ExampleControl : Control
{
public object Property1
{
get { return (object)GetValue(Property1Property); }
set { SetValue(Property1Property, value); }
}
public static readonly DependencyProperty Property1Property =
DependencyProperty.Register("Property1", typeof(object), typeof(ExampleControl), new PropertyMetadata(null));
}
}

133
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/NamescopeTest.cs

@ -0,0 +1,133 @@ @@ -0,0 +1,133 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;
using System.Xml;
using ICSharpCode.WpfDesign.XamlDom;
using NUnit.Framework;
using ICSharpCode.WpfDesign.Designer;
using ICSharpCode.WpfDesign.Designer.UIExtensions;
namespace ICSharpCode.WpfDesign.Tests.XamlDom
{
[TestFixture]
public class NamescopeTest : TestHelper
{
/// <summary>
/// NamescopeTest 1
/// </summary>
[Test]
public void NamescopeTest1()
{
var xaml= @"
<UserControl
xmlns=""http://schemas.microsoft.com/netfx/2007/xaml/presentation""
xmlns:t=""" + XamlTypeFinderTests.XamlDomTestsNamespace + @"""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
x:Name=""root""
>
<Grid x:Name=""rootGrid"" >
<Button x:Name=""aa"" />
<Button x:Name=""bb"" />
<t:ExampleControl Property1=""{x:Reference aa}"" />
</Grid>
</UserControl>";
var obj = XamlParser.Parse(new StringReader(xaml));
((FrameworkElement)obj.RootInstance).CreateVisualTree();
var example = ((FrameworkElement) obj.RootInstance).TryFindChild<ExampleControl>();
var buttonAa = ((FrameworkElement)obj.RootInstance).TryFindChild<Button>("aa");
Assert.AreEqual(example.Property1, buttonAa);
}
/// <summary>
/// NamescopeTest 2
/// </summary>
[Test]
public void NamescopeTest2()
{
var xaml = @"
<UserControl
xmlns=""http://schemas.microsoft.com/netfx/2007/xaml/presentation""
xmlns:t=""" + XamlTypeFinderTests.XamlDomTestsNamespace + @"""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
x:Name=""root""
>
<Grid x:Name=""grid"" >
<Button Content=""level0"" x:Name=""aa"" />
<t:NamscopeTestUsercontrol />
<Button Content=""level0"" x:Name=""bb"" />
<t:ExampleControl Property1=""{x:Reference aa}"" />
<t:ExampleControl x:Name=""exampleb"" Property1=""{x:Reference bb}"" />
</Grid>
</UserControl>";
object officialResult = XamlReader.Load(new XmlTextReader(new StringReader(xaml)));
((FrameworkElement)officialResult).CreateVisualTree();
var example1 = ((FrameworkElement)officialResult).TryFindChild<ExampleControl>();
var exampleb1 = ((FrameworkElement)officialResult).TryFindChild<ExampleControl>("exampleb");
var buttonAa1 = ((FrameworkElement)officialResult).TryFindChild<Button>("aa");
var buttonbb1 = ((FrameworkElement)officialResult).TryFindChild<Button>("bb");
Assert.AreEqual(example1.Property1, buttonAa1);
Assert.AreNotEqual(exampleb1.Property1, buttonbb1);
var obj = XamlParser.Parse(new StringReader(xaml));
((FrameworkElement)obj.RootInstance).CreateVisualTree();
var example2 = ((FrameworkElement)obj.RootInstance).TryFindChild<ExampleControl>();
var exampleb2 = ((FrameworkElement)obj.RootInstance).TryFindChild<ExampleControl>("exampleb");
var buttonAa2 = ((FrameworkElement)obj.RootInstance).TryFindChild<Button>("aa");
var buttonbb2 = ((FrameworkElement)obj.RootInstance).TryFindChild<Button>("bb");
Assert.AreEqual(example2.Property1, buttonAa2);
Assert.AreNotEqual(exampleb2.Property1, buttonbb2);
}
/// <summary>
/// NamescopeTest 3
/// </summary>
[Test]
public void NamescopeTest3()
{
var xaml = @"
<Grid
xmlns=""http://schemas.microsoft.com/netfx/2007/xaml/presentation""
xmlns:t=""" + XamlTypeFinderTests.XamlDomTestsNamespace + @"""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
x:Name=""root""
>
<Button Content=""level0"" x:Name=""aa"" />
<t:NamscopeTestUsercontrol />
<Button Content=""level0"" x:Name=""bb"" />
<t:ExampleControl Property1=""{x:Reference aa}"" />
<t:ExampleControl x:Name=""exampleb"" Property1=""{x:Reference bb}"" />
</Grid>";
object officialResult = XamlReader.Load(new XmlTextReader(new StringReader(xaml)));
((FrameworkElement)officialResult).CreateVisualTree();
var example1 = ((FrameworkElement)officialResult).TryFindChild<ExampleControl>();
var exampleb1 = ((FrameworkElement)officialResult).TryFindChild<ExampleControl>("exampleb");
var buttonAa1 = ((FrameworkElement)officialResult).TryFindChild<Button>("aa");
var buttonbb1 = ((FrameworkElement)officialResult).TryFindChild<Button>("bb");
Assert.AreEqual(example1.Property1, buttonAa1);
Assert.AreNotEqual(exampleb1.Property1, buttonbb1);
var obj = XamlParser.Parse(new StringReader(xaml));
((FrameworkElement)obj.RootInstance).CreateVisualTree();
var example2 = ((FrameworkElement)obj.RootInstance).TryFindChild<ExampleControl>();
var exampleb2 = ((FrameworkElement)obj.RootInstance).TryFindChild<ExampleControl>("exampleb");
var buttonAa2 = ((FrameworkElement)obj.RootInstance).TryFindChild<Button>("aa");
var buttonbb2 = ((FrameworkElement)obj.RootInstance).TryFindChild<Button>("bb");
Assert.AreEqual(example2.Property1, buttonAa2);
Assert.AreNotEqual(exampleb2.Property1, buttonbb2);
}
}
}

13
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/NamscopeTestUsercontrol.xaml

@ -0,0 +1,13 @@ @@ -0,0 +1,13 @@
<UserControl x:Class="ICSharpCode.WpfDesign.Tests.XamlDom.NamscopeTestUsercontrol"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:ICSharpCode.WpfDesign.Tests.XamlDom"
mc:Ignorable="d" x:Name="usercontrol"
d:DesignHeight="300" d:DesignWidth="300">
<Grid x:Name="grid">
<Button x:Name="aa" Content="level1" />
<Button x:Name="bb" Content="level1" />
</Grid>
</UserControl>

28
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/NamscopeTestUsercontrol.xaml.cs

@ -0,0 +1,28 @@ @@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace ICSharpCode.WpfDesign.Tests.XamlDom
{
/// <summary>
/// Interaction logic for NamscopeTestUsercontrol.xaml
/// </summary>
public partial class NamscopeTestUsercontrol : UserControl
{
public NamscopeTestUsercontrol()
{
InitializeComponent();
}
}
}

159
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/SamplesTests.cs

@ -16,7 +16,11 @@ @@ -16,7 +16,11 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.IO;
using System.Windows;
using System.Windows.Markup;
using System.Xaml;
using ICSharpCode.WpfDesign.XamlDom;
using NUnit.Framework;
@ -25,6 +29,32 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom @@ -25,6 +29,32 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom
[TestFixture]
public class SamplesTests : TestHelper
{
/// <summary>
/// Non-trivial because of: InlineCollection wrapping a string
/// </summary>
[Test]
public void Complex1()
{
TestLoading(@"
<Page
xmlns=""http://schemas.microsoft.com/netfx/2007/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
>
<Page.Resources>
<Style x:Key=""HeaderStyle"" TargetType=""TextBlock"">
<Setter Property=""Foreground"" Value=""Gray"" />
<Setter Property=""FontSize"" Value=""24"" />
</Style>
</Page.Resources>
<StackPanel Margin=""10"">
<TextBlock>Header 1</TextBlock>
<TextBlock Style=""{StaticResource HeaderStyle}"">Header 2</TextBlock>
<TextBlock>Header 3</TextBlock>
</StackPanel>
</Page>");
}
/// <summary>
/// Non-trivial because of: InlineCollection wrapping a string
/// </summary>
@ -346,6 +376,135 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom @@ -346,6 +376,135 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom
</Window>");
}
[Test]
public void XReferenceTest1()
{
TestLoading(@"<Window xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
<Canvas>
<Button x:Name=""aa""
Content=""Button""
Width=""75""
Height=""23""
Canvas.Left=""205""
Canvas.Top=""262"" />
<Button x:Name=""bb""
Content=""{Binding Path=Content,Source={x:Reference aa}}""
Width=""75""
Height=""23""
Canvas.Left=""79""
Canvas.Top=""158"" />
</Canvas>
</Window>");
}
[Test]
public void Style1()
{
TestLoading(@"<Window xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
<Canvas>
<Button Content=""Button""
Width=""75""
Height=""23"">
<Button.Style>
<Style TargetType=""Button"">
<Setter Property=""Template"">
<Setter.Value>
<ControlTemplate TargetType=""Button"">
<Grid />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Button.Style>
</Button>
</Canvas>
</Window>");
}
[Test]
public void Style2()
{
TestLoading(@"<Window xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
<Canvas>
<Button Content=""Button""
Width=""75""
Height=""23"">
<Button.Style>
<Style TargetType=""Button"">
<Setter Property=""Template"">
<Setter.Value>
<ControlTemplate TargetType=""Button"">
<Grid HorizontalAlignment=""Left"">
<Rectangle />
<TextBlock Text=""AA"" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Button.Style>
</Button>
</Canvas>
</Window>");
}
[Test]
[Ignore("Xaml writer creates different XAML")]
public void Style3()
{
TestLoading(@"<Window xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
<Canvas>
<Button Content=""Button""
Width=""75""
Height=""23"">
<Button.Style>
<Style TargetType=""Button"">
<Setter Property=""Template"">
<Setter.Value>
<ControlTemplate TargetType=""Button"">
<Grid>
<Ellipse Fill=""{TemplateBinding Background}""
Stroke=""{TemplateBinding BorderBrush}""/>
<ContentPresenter HorizontalAlignment=""Center""
VerticalAlignment=""Center""/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Button.Style>
</Button>
</Canvas>
</Window>");
}
[Test]
public void Template1()
{
TestLoading(@"<Window xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
<Canvas>
<Button Content=""Button""
Width=""75""
Height=""23"">
<Button.Template>
<ControlTemplate TargetType=""Button"">
<Grid HorizontalAlignment=""Left"">
<Rectangle />
<TextBlock Text=""AA"" />
</Grid>
</ControlTemplate>
</Button.Template>
</Button>
</Canvas>
</Window>");
}
[Test]
public void ListBox1()
{

77
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/MarkupExtensionPrinter.cs

@ -20,6 +20,9 @@ using System; @@ -20,6 +20,9 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Data;
using System.Windows.Markup;
namespace ICSharpCode.WpfDesign.XamlDom
{
@ -34,7 +37,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -34,7 +37,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
public static bool CanPrint(XamlObject obj)
{
if (obj.ElementType == typeof(System.Windows.Data.MultiBinding) ||
obj.ElementType == typeof(System.Windows.Data.PriorityBinding)) {
obj.ElementType == typeof(System.Windows.Data.PriorityBinding)) {
return false;
}
@ -51,7 +54,37 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -51,7 +54,37 @@ namespace ICSharpCode.WpfDesign.XamlDom
sb.Append(obj.GetNameForMarkupExtension());
bool first = true;
foreach (var property in obj.Properties) {
var properties = obj.Properties.ToList();
if (obj.ElementType == typeof(Binding)){
var p=obj.Properties.FirstOrDefault(x=>x.PropertyName=="Path");
if (p!=null && p.IsSet) {
sb.Append(" ");
AppendPropertyValue(sb, p.PropertyValue);
properties.Remove(p);
first = false;
}
}
else if (obj.ElementType == typeof(Reference)){
var p=obj.Properties.FirstOrDefault(x=>x.PropertyName=="Name");
if (p!=null && p.IsSet) {
sb.Append(" ");
AppendPropertyValue(sb, p.PropertyValue);
properties.Remove(p);
first = false;
}
}
else if (obj.ElementType == typeof(StaticResourceExtension)){
var p=obj.Properties.FirstOrDefault(x=>x.PropertyName=="ResourceKey");
if (p!=null && p.IsSet) {
sb.Append(" ");
AppendPropertyValue(sb, p.PropertyValue);
properties.Remove(p);
first = false;
}
}
foreach (var property in properties) {
if (!property.IsSet) continue;
if (first)
@ -63,29 +96,33 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -63,29 +96,33 @@ namespace ICSharpCode.WpfDesign.XamlDom
sb.Append(property.GetNameForMarkupExtension());
sb.Append("=");
var value = property.PropertyValue;
var textValue = value as XamlTextValue;
if (textValue != null) {
string text = textValue.Text;
bool containsSpace = text.Contains(' ');
if(containsSpace) {
sb.Append('\'');
}
sb.Append(text.Replace("\\", "\\\\"));
if(containsSpace) {
sb.Append('\'');
}
} else if (value is XamlObject) {
sb.Append(Print(value as XamlObject));
}
AppendPropertyValue(sb, property.PropertyValue);
}
sb.Append("}");
return sb.ToString();
}
private static void AppendPropertyValue(StringBuilder sb, XamlPropertyValue value)
{
var textValue = value as XamlTextValue;
if (textValue != null) {
string text = textValue.Text;
bool containsSpace = text.Contains(' ');
if(containsSpace) {
sb.Append('\'');
}
sb.Append(text.Replace("\\", "\\\\"));
if(containsSpace) {
sb.Append('\'');
}
} else if (value is XamlObject) {
sb.Append(Print(value as XamlObject));
}
}
private static bool CanPrint(XamlObject obj, bool isNested, XamlObject nonMarkupExtensionParent)
{
if ((isNested || obj.ParentObject == nonMarkupExtensionParent) && IsStaticResourceThatReferencesLocalResource(obj, nonMarkupExtensionParent)) {

28
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/NameScopeHelper.cs

@ -34,11 +34,11 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -34,11 +34,11 @@ namespace ICSharpCode.WpfDesign.XamlDom
/// <param name="namedObject">The object where the name was changed.</param>
/// <param name="oldName">The old name.</param>
/// <param name="newName">The new name.</param>
internal static void NameChanged(XamlObject namedObject, string oldName, string newName)
public static void NameChanged(XamlObject namedObject, string oldName, string newName)
{
var obj = namedObject;
while (obj != null) {
var nameScope = GetNameScopeFromObject(obj.Instance);
var nameScope = GetNameScopeFromObject(obj);
if (nameScope != null) {
if (oldName != null) {
try {
@ -69,13 +69,25 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -69,13 +69,25 @@ namespace ICSharpCode.WpfDesign.XamlDom
/// </summary>
/// <param name="obj">The object to get the XAML namescope for.</param>
/// <returns>A XAML namescope, as an <see cref="INameScope"/> instance.</returns>
public static INameScope GetNameScopeFromObject(object obj)
public static INameScope GetNameScopeFromObject(XamlObject obj)
{
var nameScope = obj as INameScope;
if (nameScope == null) {
var depObj = obj as DependencyObject;
if (depObj != null)
nameScope = NameScope.GetNameScope(depObj);
INameScope nameScope = null;
while (obj != null)
{
nameScope = obj.Instance as INameScope;
if (nameScope == null)
{
var xamlObj = obj.ParentObject != null ? obj.ParentObject : obj;
var depObj = xamlObj.Instance as DependencyObject;
if (depObj != null)
nameScope = NameScope.GetNameScope(depObj);
if (nameScope != null)
break;
}
obj = obj.ParentObject;
}
return nameScope;

62
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/TemplateHelper.cs

@ -0,0 +1,62 @@ @@ -0,0 +1,62 @@
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;
using System.Xml;
using System.Xml.XPath;
namespace ICSharpCode.WpfDesign.XamlDom
{
public static class TemplateHelper
{
public static FrameworkTemplate GetFrameworkTemplate(XmlElement xmlElement)
{
var nav = xmlElement.CreateNavigator();
var ns = new Dictionary<string, string>();
while (true)
{
var nsInScope = nav.GetNamespacesInScope(XmlNamespaceScope.ExcludeXml);
foreach (var ak in nsInScope)
{
if (!ns.ContainsKey(ak.Key) && ak.Key != "")
ns.Add(ak.Key, ak.Value);
}
if (!nav.MoveToParent())
break;
}
foreach (var dictentry in ns)
{
xmlElement.SetAttribute("xmlns:" + dictentry.Key, dictentry.Value);
}
var xaml = xmlElement.OuterXml;
StringReader stringReader = new StringReader(xaml);
XmlReader xmlReader = XmlReader.Create(stringReader);
return (FrameworkTemplate)XamlReader.Load(xmlReader);
}
}
}

1
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/WpfDesign.XamlDom.csproj

@ -76,6 +76,7 @@ @@ -76,6 +76,7 @@
<Compile Include="MarkupExtensionPrinter.cs" />
<Compile Include="NameScopeHelper.cs" />
<Compile Include="PositionXmlDocument.cs" />
<Compile Include="TemplateHelper.cs" />
<Compile Include="XamlConstants.cs" />
<Compile Include="XamlDocument.cs" />
<Compile Include="XamlLoadException.cs" />

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObject.cs

@ -548,6 +548,8 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -548,6 +548,8 @@ namespace ICSharpCode.WpfDesign.XamlDom
if (wrapper != null) {
return wrapper.ProvideValue();
}
if (this.ParentObject.ElementType == typeof (Setter) && this.ElementType == typeof(DynamicResourceExtension))
return Instance;
return (Instance as MarkupExtension).ProvideValue(ServiceProvider);
}

60
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObjectServiceProvider.cs

@ -29,7 +29,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -29,7 +29,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
/// A service provider that provides the IProvideValueTarget and IXamlTypeResolver services.
/// No other services (e.g. from the document's service provider) are offered.
/// </summary>
public class XamlObjectServiceProvider : IServiceProvider, IProvideValueTarget, IXamlSchemaContextProvider, IAmbientProvider
public class XamlObjectServiceProvider : IServiceProvider, IXamlNameResolver, IProvideValueTarget, IXamlSchemaContextProvider, IAmbientProvider
{
/// <summary>
/// Creates a new XamlObjectServiceProvider instance.
@ -71,6 +71,11 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -71,6 +71,11 @@ namespace ICSharpCode.WpfDesign.XamlDom
if (serviceType == typeof(IAmbientProvider)) {
return this;
}
if (serviceType == typeof(IXamlNameResolver))
{
return this;
}
return null;
}
@ -181,5 +186,58 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -181,5 +186,58 @@ namespace ICSharpCode.WpfDesign.XamlDom
}
#endregion
#region IXamlNameResolver
public object Resolve(string name)
{
INameScope ns = null;
var xamlObj = this.XamlObject;
while (xamlObj != null)
{
ns = NameScopeHelper.GetNameScopeFromObject(xamlObj);
if (ns != null) {
var obj = ns.FindName(name);
if (obj != null)
return obj;
}
xamlObj = xamlObj.ParentObject;
}
return null;
}
public object Resolve(string name, out bool isFullyInitialized)
{
var ret = Resolve(name);
isFullyInitialized = ret != null;
return ret;
}
public object GetFixupToken(IEnumerable<string> names)
{
return null;
}
public object GetFixupToken(IEnumerable<string> names, bool canAssignDirectly)
{
return null;
}
public IEnumerable<KeyValuePair<string, object>> GetAllNamesAndValuesInScope()
{
return null;
}
public bool IsFixupTokenAvailable
{
get { return false; }
}
public event EventHandler OnNameScopeInitializationComplete;
#endregion
}
}

38
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlParser.cs

@ -192,6 +192,15 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -192,6 +192,15 @@ namespace ICSharpCode.WpfDesign.XamlDom
XamlObject ParseObject(XmlElement element)
{
Type elementType = settings.TypeFinder.GetType(element.NamespaceURI, element.LocalName);
if (typeof (FrameworkTemplate).IsAssignableFrom(elementType))
{
var xamlObj = new XamlObject(document, element, elementType, TemplateHelper.GetFrameworkTemplate(element));
xamlObj.ParentObject = currentXamlObject;
return xamlObj;
}
if (elementType == null) {
elementType = settings.TypeFinder.GetType(element.NamespaceURI, element.LocalName + "Extension");
if (elementType == null) {
@ -551,12 +560,27 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -551,12 +560,27 @@ namespace ICSharpCode.WpfDesign.XamlDom
return null;
}
internal static XamlPropertyInfo GetPropertyInfo(XamlTypeFinder typeFinder, object elementInstance, Type elementType, string xmlNamespace, string localName)
internal static XamlPropertyInfo GetPropertyInfo(XamlTypeFinder typeFinder, object elementInstance, Type elementType, string xmlNamespace, string localName, bool tryFindAllProperties = false)
{
string typeName, propertyName;
SplitQualifiedIdentifier(localName, out typeName, out propertyName);
Type propertyType = FindType(typeFinder, xmlNamespace, typeName);
if (elementType == propertyType || propertyType.IsAssignableFrom(elementType)) {
//Tries to Find All properties, even if they are not attached (For Setters, Bindings, ...)
if (tryFindAllProperties)
{
XamlPropertyInfo propertyInfo = null;
try
{
propertyInfo = FindProperty(elementInstance, propertyType, propertyName);
}
catch (Exception ex)
{ }
if (propertyInfo != null)
return propertyInfo;
}
if (elementType.IsAssignableFrom(propertyType) || propertyType.IsAssignableFrom(elementType)) {
return FindProperty(elementInstance, propertyType, propertyName);
} else {
// This is an attached property
@ -615,7 +639,8 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -615,7 +639,8 @@ namespace ICSharpCode.WpfDesign.XamlDom
static bool IsElementChildACollectionForProperty(XamlTypeFinder typeFinder, XmlElement element, XamlPropertyInfo propertyInfo)
{
return element.ChildNodes.Count == 1 && propertyInfo.ReturnType.IsAssignableFrom(FindType(typeFinder, element.FirstChild.NamespaceURI, element.FirstChild.LocalName));
var nodes = element.ChildNodes.Cast<XmlNode>().Where(x => !(x is XmlWhitespace)).ToList();
return nodes.Count == 1 && propertyInfo.ReturnType.IsAssignableFrom(FindType(typeFinder, nodes[0].NamespaceURI, nodes[0].LocalName));
}
void ParseObjectChildElementAsPropertyElement(XamlObject obj, XmlElement element, XamlPropertyInfo defaultProperty)
@ -645,7 +670,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -645,7 +670,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
isElementChildACollectionForProperty = IsElementChildACollectionForProperty(settings.TypeFinder, element, propertyInfo);
if (isElementChildACollectionForProperty)
collectionProperty.ParserSetPropertyElement((XmlElement)element.FirstChild);
collectionProperty.ParserSetPropertyElement((XmlElement)element.ChildNodes.Cast<XmlNode>().Where(x => !(x is XmlWhitespace)).First());
else {
collectionInstance = collectionProperty.propertyInfo.GetValue(obj.Instance);
collectionProperty.ParserSetPropertyElement(element);
@ -756,13 +781,14 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -756,13 +781,14 @@ namespace ICSharpCode.WpfDesign.XamlDom
if(xmlnsAttribute!=null)
element.Attributes.Remove(xmlnsAttribute);
RemoveRootNamespacesFromNodeAndChildNodes(root, element);
XamlParser parser = new XamlParser();
parser.settings = settings;
parser.errorSink = (IXamlErrorSink)settings.ServiceProvider.GetService(typeof(IXamlErrorSink));
parser.document = root.OwnerDocument;
var xamlObject = parser.ParseObject(element as XmlElement);
RemoveRootNamespacesFromNodeAndChildNodes(root, element);
if (xamlObject != null)
return xamlObject;
}

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs

@ -409,7 +409,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -409,7 +409,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
parentObject.XmlElement.AppendChild(parentNode);
}
else if (parentNode.ChildNodes.Count > 0)
else if (parentNode.ChildNodes.Cast<XmlNode>().Where(x => !(x is XmlWhitespace)).Count() > 0)
throw new XamlLoadException("Collection property node must have no children when adding collection element.");
parentNode.AppendChild(newChildNode);

5
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlTypeFinder.cs

@ -162,7 +162,12 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -162,7 +162,12 @@ namespace ICSharpCode.WpfDesign.XamlDom
assembly = name.Substring("assembly=".Length);
}
XamlNamespace ns = new XamlNamespace(null, xmlNamespace);
Assembly asm = LoadAssembly(assembly);
if (asm == null && assembly == "mscorlib")
asm = typeof (Boolean).Assembly;
if (asm != null) {
AddMappingToNamespace(ns, new AssemblyNamespaceMapping(asm, namespaceName));
}

3
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlTypeResolverProvider.cs

@ -111,7 +111,8 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -111,7 +111,8 @@ namespace ICSharpCode.WpfDesign.XamlDom
obj = obj.ParentObject;
}
if (propertyName.Contains(".")) {
return XamlParser.GetPropertyInfo(document.TypeFinder, null, elementType, propertyNamespace, propertyName);
var allPropertiesAllowed = this.containingObject is XamlObject && (((XamlObject)this.containingObject).ElementType == typeof(Setter) || ((XamlObject)this.containingObject).IsMarkupExtension);
return XamlParser.GetPropertyInfo(document.TypeFinder, null, elementType, propertyNamespace, propertyName, allPropertiesAllowed);
} else if (elementType != null) {
return XamlParser.FindProperty(null, elementType, propertyName);
} else {

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementOperation.cs

@ -218,7 +218,7 @@ namespace ICSharpCode.WpfDesign @@ -218,7 +218,7 @@ namespace ICSharpCode.WpfDesign
if (element is FrameworkElement && size.Width < ((FrameworkElement)element).MinWidth)
size.Width = ((FrameworkElement)element).MinWidth;
if (element is FrameworkElement && size.Height < ((FrameworkElement)element).MinHeight)
size.Height = ((FrameworkElement)element).Height;
size.Height = ((FrameworkElement)element).MinHeight;
return size;
}

Loading…
Cancel
Save