jkuehner 11 years ago
parent
commit
05bce656e4
  1. 214
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs
  2. 4
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/UIHelpers.cs
  3. 9
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/WpfDesign.Tests.csproj
  4. 23
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/ExampleControl.cs
  5. 132
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/NamescopeTest.cs
  6. 13
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/NamscopeTestUsercontrol.xaml
  7. 28
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/NamscopeTestUsercontrol.xaml.cs

214
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,13 +227,13 @@ namespace ICSharpCode.WpfDesign.Designer @@ -227,13 +227,13 @@ 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;
itemPos.Ymax = pos.Y + pos.Height;
return itemPos;
return itemPos;
}
public static void WrapItemsNewContainer(IEnumerable<DesignItem> items, Type containerType)
@ -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,8 +355,8 @@ namespace ICSharpCode.WpfDesign.Designer @@ -355,8 +355,8 @@ 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");
List<ItemPos> itemList = new List<ItemPos>();
@ -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();
}
}
}

4
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/UIHelpers.cs

@ -25,7 +25,7 @@ using System.Windows.Media; @@ -25,7 +25,7 @@ using System.Windows.Media;
namespace ICSharpCode.WpfDesign.Designer
{
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/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));
}
}

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

@ -0,0 +1,132 @@ @@ -0,0 +1,132 @@
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;
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();
}
}
}
Loading…
Cancel
Save