7 changed files with 314 additions and 109 deletions
@ -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)); |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
@ -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); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -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> |
||||||
@ -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…
Reference in new issue