コード例 #1
0
        public void XamlLoadEventsTest()
        {
            string text = @"
            <test:LoaderTestElement
                xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
                xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
                xmlns:test='clr-namespace:Granular.Presentation.Tests.Markup;assembly=Granular.Presentation.Tests'>

                <test:LoaderTestElement x:Name='element1' Action1='Handler1' Action2='Handler2'/>
                <test:LoaderTestElement x:Name='element2' test:LoaderTestElement.Action1='Handler3' test:LoaderTestElement.Action2='Handler4'/>

            </test:LoaderTestElement>";

            LoaderTestTopElement root = new LoaderTestTopElement();

            XamlLoader.Load(root, XamlParser.Parse(text));

            LoaderTestElement element1 = NameScope.GetNameScope(root).FindName("element1") as LoaderTestElement;
            LoaderTestElement element2 = NameScope.GetNameScope(root).FindName("element2") as LoaderTestElement;

            element1.RaiseAction1();
            element1.RaiseAction2();

            element2.RaiseAction1();
            element2.RaiseAction1();
            element2.RaiseAction2();
            element2.RaiseAction2();

            Assert.IsTrue(root != null);
            Assert.AreEqual(1, root.Handler1Calls);
            //Assert.AreEqual(1, root.Handler2Calls);
            Assert.AreEqual(2, root.Handler3Calls);
            //Assert.AreEqual(2, root.Handler4Calls);
        }
コード例 #2
0
ファイル: XamlLoaderTest.cs プロジェクト: will8886/Granular
        public void XamlLoadKeyElementTest()
        {
            string text = @"
            <ResourceDictionary xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:test='clr-namespace:Granular.Presentation.Tests.Markup;assembly=Granular.Presentation.Tests'>
                <test:LoaderTestElement Value1='1' Value2='2'>
                    <x:Key>
                        <test:LoaderTestElement Value1='3' Value2='4'/>
                    </x:Key>
                </test:LoaderTestElement>
            </ResourceDictionary>";

            XamlElement        rootElement = XamlParser.Parse(text);
            ResourceDictionary dictionary  = XamlLoader.Load(rootElement) as ResourceDictionary;

            Assert.IsNotNull(dictionary);
            Assert.AreEqual(1, dictionary.Count);

            LoaderTestElement key   = (LoaderTestElement)dictionary.Keys.First();
            LoaderTestElement value = (LoaderTestElement)dictionary[key];

            Assert.AreEqual(1, value.Value1);
            Assert.AreEqual(2, value.Value2);

            Assert.AreEqual(3, key.Value1);
            Assert.AreEqual(4, key.Value2);
        }
コード例 #3
0
        public void XamlLoadNameDirectiveTest()
        {
            string text = @"
            <test:LoaderTestElement xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:test='clr-namespace:Granular.Presentation.Tests.Markup;assembly=Granular.Presentation.Tests'>
                <test:LoaderTestElement x:Name='element1' Value1='1'/>
                <test:LoaderTestElement x:Name='element2' Value1='2'/>
            </test:LoaderTestElement>";

            LoaderTestElement root = XamlLoader.Load(XamlParser.Parse(text)) as LoaderTestElement;

            LoaderTestElement element1 = NameScope.GetNameScope(root).FindName("element1") as LoaderTestElement;
            LoaderTestElement element2 = NameScope.GetNameScope(root).FindName("element2") as LoaderTestElement;

            Assert.IsTrue(element1 != null);
            Assert.IsTrue(element2 != null);
            Assert.AreEqual(1, element1.Value1);
            Assert.AreEqual(2, element2.Value1);
        }
コード例 #4
0
        public void XamlLoadFrameworkElementFactoryTest()
        {
            string text = @"
            <test:LoaderTestFactoryElement xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:test='clr-namespace:Granular.Presentation.Tests.Markup;assembly=Granular.Presentation.Tests'>
                <test:LoaderTestElement Value1='1' Value2='2'/>
            </test:LoaderTestFactoryElement>";

            XamlElement rootElement = XamlParser.Parse(text);
            object      root1       = XamlLoader.Load(rootElement);

            Assert.IsTrue(root1 is LoaderTestFactoryElement);
            Assert.IsTrue(((LoaderTestFactoryElement)root1).Factory != null);

            LoaderTestElement contentElement = ((LoaderTestFactoryElement)root1).Factory.CreateElement(null) as LoaderTestElement;

            Assert.IsNotNull(contentElement);
            Assert.AreEqual(1, contentElement.Value1);
            Assert.AreEqual(2, contentElement.Value2);
        }
コード例 #5
0
ファイル: XamlLoaderTest.cs プロジェクト: will8886/Granular
        public void XamlLoadSharedTest()
        {
            string text = @"
            <ResourceDictionary xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:test='clr-namespace:Granular.Presentation.Tests.Markup;assembly=Granular.Presentation.Tests'>
                <test:LoaderTestElement x:Shared='false' x:Key='item1' Value1='1' Value2='2'/>
                <test:LoaderTestElement x:Shared='true' x:Key='item2' Value1='3' Value2='4'/>
            </ResourceDictionary>";

            XamlElement        rootElement = XamlParser.Parse(text);
            ResourceDictionary dictionary  = XamlLoader.Load(rootElement) as ResourceDictionary;

            Assert.IsNotNull(dictionary);
            Assert.IsTrue(dictionary.Contains("item1"));
            Assert.IsTrue(dictionary.Contains("item2"));

            LoaderTestElement item1a = dictionary.GetValue("item1") as LoaderTestElement;

            Assert.IsNotNull(item1a);
            Assert.AreEqual(1, ((LoaderTestElement)item1a).Value1);
            Assert.AreEqual(2, ((LoaderTestElement)item1a).Value2);

            LoaderTestElement item1b = dictionary.GetValue("item1") as LoaderTestElement;

            Assert.IsFalse(ReferenceEquals(item1a, item1b));
            Assert.IsNotNull(item1b);
            Assert.AreNotEqual(item1a, item1b);
            Assert.AreEqual(1, ((LoaderTestElement)item1b).Value1);
            Assert.AreEqual(2, ((LoaderTestElement)item1b).Value2);

            LoaderTestElement item2a = dictionary.GetValue("item2") as LoaderTestElement;

            Assert.IsNotNull(item2a);
            Assert.AreEqual(3, ((LoaderTestElement)item2a).Value1);
            Assert.AreEqual(4, ((LoaderTestElement)item2a).Value2);

            LoaderTestElement item2b = dictionary.GetValue("item2") as LoaderTestElement;

            Assert.IsTrue(ReferenceEquals(item2a, item2b));
        }