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. 23
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/SnaplinePlacementBehavior.cs
  9. 1
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TextBlockRightClickContextMenu.xaml.cs
  10. 2
      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. 8
      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. 47
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/MarkupExtensionPrinter.cs
  29. 24
      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;
using ICSharpCode.WpfDesign.Designer.Converters; using ICSharpCode.WpfDesign.Designer.Converters;
using System.Globalization; using System.Globalization;
using System.Windows.Data; using System.Windows.Data;
using ICSharpCode.WpfDesign.Designer.UIExtensions;
namespace ICSharpCode.WpfDesign.Designer.Controls namespace ICSharpCode.WpfDesign.Designer.Controls
{ {

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

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

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

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

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

@ -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 @@
// 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 @@
// 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;
using ICSharpCode.WpfDesign.Designer.Controls; using ICSharpCode.WpfDesign.Designer.Controls;
using ICSharpCode.WpfDesign.Extensions; using ICSharpCode.WpfDesign.Extensions;
using System.Collections.Generic; using System.Collections.Generic;
using ICSharpCode.WpfDesign.Designer.UIExtensions;
namespace ICSharpCode.WpfDesign.Designer.Extensions namespace ICSharpCode.WpfDesign.Designer.Extensions
{ {

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

@ -19,16 +19,11 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text;
using System.Windows; using System.Windows;
using ICSharpCode.WpfDesign.Extensions;
using System.ComponentModel;
using ICSharpCode.WpfDesign.Adorners; using ICSharpCode.WpfDesign.Adorners;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Shapes; using System.Windows.Shapes;
using System.Windows.Automation.Peers;
using System.Windows.Controls.Primitives;
using System.Diagnostics; using System.Diagnostics;
using System.Windows.Input; using System.Windows.Input;
@ -36,6 +31,20 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
{ {
public class SnaplinePlacementBehavior : RasterPlacementBehavior 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; AdornerPanel adornerPanel;
Canvas surface; Canvas surface;
List<Snapline> horizontalMap; List<Snapline> horizontalMap;
@ -217,7 +226,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
AddLines(containerRect, 0, false); AddLines(containerRect, 0, false);
foreach (var item in AllDesignItems() /* ExtendedItem.ContentProperty.CollectionElements */ 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) { if (item != null) {
var bounds = GetPosition(operation, item); var bounds = GetPosition(operation, item);
@ -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;
using System.Linq; using System.Linq;
using System.Windows; using System.Windows;
using ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.FormatedTextEditor; using ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.FormatedTextEditor;
using ICSharpCode.WpfDesign.Designer.UIExtensions;
namespace ICSharpCode.WpfDesign.Designer.Extensions namespace ICSharpCode.WpfDesign.Designer.Extensions
{ {

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

@ -119,7 +119,7 @@ namespace ICSharpCode.WpfDesign.Designer
} }
} }
internal static void CreateVisualTree(this UIElement element) public static void CreateVisualTree(this UIElement element)
{ {
try try
{ {

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

@ -20,6 +20,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using ICSharpCode.WpfDesign.Designer.UIExtensions;
namespace ICSharpCode.WpfDesign.Designer.OutlineView 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;
using System.Windows.Documents; using System.Windows.Documents;
using System.Windows.Media; using System.Windows.Media;
using ICSharpCode.WpfDesign.Designer.Xaml; using ICSharpCode.WpfDesign.Designer.Xaml;
using ICSharpCode.WpfDesign.Designer.UIExtensions;
namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.FormatedTextEditor 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;
using System.Windows.Media; using System.Windows.Media;
using System.Diagnostics; using System.Diagnostics;
using ICSharpCode.WpfDesign.Designer.Controls; using ICSharpCode.WpfDesign.Designer.Controls;
using ICSharpCode.WpfDesign.Designer.UIExtensions;
namespace ICSharpCode.WpfDesign.Designer.ThumbnailView namespace ICSharpCode.WpfDesign.Designer.ThumbnailView
{ {

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

@ -145,5 +145,13 @@ namespace ICSharpCode.WpfDesign.Designer
return "Arrange Bottom"; 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;
using System.Windows; using System.Windows;
using System.Windows.Media; 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) public static DependencyObject GetParentObject(this DependencyObject child)
{ {
@ -85,7 +85,7 @@ namespace ICSharpCode.WpfDesign.Designer
return null; 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; if (parent == null) return null;
T foundChild = null; T foundChild = null;

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

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

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

@ -105,7 +105,7 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
} }
if (_context.RootItem != null && !string.IsNullOrEmpty(site.Name)) { 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) { if (nameScope != null) {
// The object will be a part of the RootItem namescope, remove local namescope if set // 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;
using System.Diagnostics; using System.Diagnostics;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Windows;
using ICSharpCode.WpfDesign.XamlDom; using ICSharpCode.WpfDesign.XamlDom;
using ICSharpCode.WpfDesign.Designer.Services; using ICSharpCode.WpfDesign.Designer.Services;
using System.Collections.Specialized; using System.Collections.Specialized;
@ -174,6 +175,8 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
void RemoveInternal(int index, XamlDesignItem item) void RemoveInternal(int index, XamlDesignItem item)
{ {
NameScopeHelper.NameChanged(item.XamlObject, item.Name, null);
Debug.Assert(property.CollectionElements[index] == item.XamlObject); Debug.Assert(property.CollectionElements[index] == item.XamlObject);
property.CollectionElements.RemoveAt(index); property.CollectionElements.RemoveAt(index);
@ -187,6 +190,8 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
if (CollectionChanged != null) if (CollectionChanged != null)
CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, index)); CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, index));
NameScopeHelper.NameChanged(item.XamlObject, null, item.Name);
} }
sealed class InsertAction : ITransactionItem sealed class InsertAction : ITransactionItem

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

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

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

@ -44,7 +44,7 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
button.Properties.GetProperty("Content").SetValue(new StaticResourceExtension()); button.Properties.GetProperty("Content").SetValue(new StaticResourceExtension());
button.Properties.GetProperty("Content").Value.Properties["ResourceKey"].SetValue("MyBrush"); button.Properties.GetProperty("Content").Value.Properties["ResourceKey"].SetValue("MyBrush");
// TODO : maybe we should support positional arguments from ctors as well => {StaticResource 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] [Test]

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

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

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

@ -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 @@
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 @@
<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 @@
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 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
using System;
using System.IO; using System.IO;
using System.Windows;
using System.Windows.Markup;
using System.Xaml;
using ICSharpCode.WpfDesign.XamlDom; using ICSharpCode.WpfDesign.XamlDom;
using NUnit.Framework; using NUnit.Framework;
@ -25,6 +29,32 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom
[TestFixture] [TestFixture]
public class SamplesTests : TestHelper 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> /// <summary>
/// Non-trivial because of: InlineCollection wrapping a string /// Non-trivial because of: InlineCollection wrapping a string
/// </summary> /// </summary>
@ -346,6 +376,135 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom
</Window>"); </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] [Test]
public void ListBox1() public void ListBox1()
{ {

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

@ -20,6 +20,9 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Windows;
using System.Windows.Data;
using System.Windows.Markup;
namespace ICSharpCode.WpfDesign.XamlDom namespace ICSharpCode.WpfDesign.XamlDom
{ {
@ -51,7 +54,37 @@ namespace ICSharpCode.WpfDesign.XamlDom
sb.Append(obj.GetNameForMarkupExtension()); sb.Append(obj.GetNameForMarkupExtension());
bool first = true; 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 (!property.IsSet) continue;
if (first) if (first)
@ -63,7 +96,14 @@ namespace ICSharpCode.WpfDesign.XamlDom
sb.Append(property.GetNameForMarkupExtension()); sb.Append(property.GetNameForMarkupExtension());
sb.Append("="); sb.Append("=");
var value = property.PropertyValue; AppendPropertyValue(sb, property.PropertyValue);
}
sb.Append("}");
return sb.ToString();
}
private static void AppendPropertyValue(StringBuilder sb, XamlPropertyValue value)
{
var textValue = value as XamlTextValue; var textValue = value as XamlTextValue;
if (textValue != null) { if (textValue != null) {
string text = textValue.Text; string text = textValue.Text;
@ -82,9 +122,6 @@ namespace ICSharpCode.WpfDesign.XamlDom
sb.Append(Print(value as XamlObject)); sb.Append(Print(value as XamlObject));
} }
} }
sb.Append("}");
return sb.ToString();
}
private static bool CanPrint(XamlObject obj, bool isNested, XamlObject nonMarkupExtensionParent) private static bool CanPrint(XamlObject obj, bool isNested, XamlObject nonMarkupExtensionParent)
{ {

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

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

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

@ -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 @@
<Compile Include="MarkupExtensionPrinter.cs" /> <Compile Include="MarkupExtensionPrinter.cs" />
<Compile Include="NameScopeHelper.cs" /> <Compile Include="NameScopeHelper.cs" />
<Compile Include="PositionXmlDocument.cs" /> <Compile Include="PositionXmlDocument.cs" />
<Compile Include="TemplateHelper.cs" />
<Compile Include="XamlConstants.cs" /> <Compile Include="XamlConstants.cs" />
<Compile Include="XamlDocument.cs" /> <Compile Include="XamlDocument.cs" />
<Compile Include="XamlLoadException.cs" /> <Compile Include="XamlLoadException.cs" />

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

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

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

@ -29,7 +29,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
/// A service provider that provides the IProvideValueTarget and IXamlTypeResolver services. /// A service provider that provides the IProvideValueTarget and IXamlTypeResolver services.
/// No other services (e.g. from the document's service provider) are offered. /// No other services (e.g. from the document's service provider) are offered.
/// </summary> /// </summary>
public class XamlObjectServiceProvider : IServiceProvider, IProvideValueTarget, IXamlSchemaContextProvider, IAmbientProvider public class XamlObjectServiceProvider : IServiceProvider, IXamlNameResolver, IProvideValueTarget, IXamlSchemaContextProvider, IAmbientProvider
{ {
/// <summary> /// <summary>
/// Creates a new XamlObjectServiceProvider instance. /// Creates a new XamlObjectServiceProvider instance.
@ -71,6 +71,11 @@ namespace ICSharpCode.WpfDesign.XamlDom
if (serviceType == typeof(IAmbientProvider)) { if (serviceType == typeof(IAmbientProvider)) {
return this; return this;
} }
if (serviceType == typeof(IXamlNameResolver))
{
return this;
}
return null; return null;
} }
@ -181,5 +186,58 @@ namespace ICSharpCode.WpfDesign.XamlDom
} }
#endregion #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
XamlObject ParseObject(XmlElement element) XamlObject ParseObject(XmlElement element)
{ {
Type elementType = settings.TypeFinder.GetType(element.NamespaceURI, element.LocalName); 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) { if (elementType == null) {
elementType = settings.TypeFinder.GetType(element.NamespaceURI, element.LocalName + "Extension"); elementType = settings.TypeFinder.GetType(element.NamespaceURI, element.LocalName + "Extension");
if (elementType == null) { if (elementType == null) {
@ -551,12 +560,27 @@ namespace ICSharpCode.WpfDesign.XamlDom
return null; 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; string typeName, propertyName;
SplitQualifiedIdentifier(localName, out typeName, out propertyName); SplitQualifiedIdentifier(localName, out typeName, out propertyName);
Type propertyType = FindType(typeFinder, xmlNamespace, typeName); 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); return FindProperty(elementInstance, propertyType, propertyName);
} else { } else {
// This is an attached property // This is an attached property
@ -615,7 +639,8 @@ namespace ICSharpCode.WpfDesign.XamlDom
static bool IsElementChildACollectionForProperty(XamlTypeFinder typeFinder, XmlElement element, XamlPropertyInfo propertyInfo) 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) void ParseObjectChildElementAsPropertyElement(XamlObject obj, XmlElement element, XamlPropertyInfo defaultProperty)
@ -645,7 +670,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
isElementChildACollectionForProperty = IsElementChildACollectionForProperty(settings.TypeFinder, element, propertyInfo); isElementChildACollectionForProperty = IsElementChildACollectionForProperty(settings.TypeFinder, element, propertyInfo);
if (isElementChildACollectionForProperty) if (isElementChildACollectionForProperty)
collectionProperty.ParserSetPropertyElement((XmlElement)element.FirstChild); collectionProperty.ParserSetPropertyElement((XmlElement)element.ChildNodes.Cast<XmlNode>().Where(x => !(x is XmlWhitespace)).First());
else { else {
collectionInstance = collectionProperty.propertyInfo.GetValue(obj.Instance); collectionInstance = collectionProperty.propertyInfo.GetValue(obj.Instance);
collectionProperty.ParserSetPropertyElement(element); collectionProperty.ParserSetPropertyElement(element);
@ -756,13 +781,14 @@ namespace ICSharpCode.WpfDesign.XamlDom
if(xmlnsAttribute!=null) if(xmlnsAttribute!=null)
element.Attributes.Remove(xmlnsAttribute); element.Attributes.Remove(xmlnsAttribute);
RemoveRootNamespacesFromNodeAndChildNodes(root, element);
XamlParser parser = new XamlParser(); XamlParser parser = new XamlParser();
parser.settings = settings; parser.settings = settings;
parser.errorSink = (IXamlErrorSink)settings.ServiceProvider.GetService(typeof(IXamlErrorSink)); parser.errorSink = (IXamlErrorSink)settings.ServiceProvider.GetService(typeof(IXamlErrorSink));
parser.document = root.OwnerDocument; parser.document = root.OwnerDocument;
var xamlObject = parser.ParseObject(element as XmlElement); var xamlObject = parser.ParseObject(element as XmlElement);
RemoveRootNamespacesFromNodeAndChildNodes(root, element);
if (xamlObject != null) if (xamlObject != null)
return xamlObject; return xamlObject;
} }

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

@ -409,7 +409,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
parentObject.XmlElement.AppendChild(parentNode); 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."); throw new XamlLoadException("Collection property node must have no children when adding collection element.");
parentNode.AppendChild(newChildNode); parentNode.AppendChild(newChildNode);

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

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

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

@ -111,7 +111,8 @@ namespace ICSharpCode.WpfDesign.XamlDom
obj = obj.ParentObject; obj = obj.ParentObject;
} }
if (propertyName.Contains(".")) { 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) { } else if (elementType != null) {
return XamlParser.FindProperty(null, elementType, propertyName); return XamlParser.FindProperty(null, elementType, propertyName);
} else { } else {

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

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

Loading…
Cancel
Save