Example #1
0
        public void UserControlNamescope4()
        {
            UserControl4Container ucc = new UserControl4Container();

            // the name defined in the definition namescope for the usercontrol is visible
            Assert.IsNotNull(ucc.FindName("localNameForUserControl4"), "1");

            // the overridden name takes priority here
            Assert.IsNotNull(ucc.FindName("containerLocalName"), "2");

            // see what happens when we add two
            // UserControl4's with their default names
            // into the same canvas.
            Canvas c = (Canvas)XamlReader.Load(@"
<Canvas
    xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
    xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" />
");

            c.Children.Add(new UserControl4());
            Assert.Throws <ArgumentException> (() => c.Children.Add(new UserControl4()), "3");

            // add them to a non-xamlreader created canvas
            Canvas c2 = new Canvas();

            c2.Children.Add(new UserControl4());
            c2.Children.Add(new UserControl4());

            // and then add that canvas to a xamlreader created canvas.
            c = (Canvas)XamlReader.Load(@"
<Canvas
    xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
    xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" />
");

            Assert.Throws <ArgumentException> (() => c.Children.Add(c2), "4");

            // add two of them but set the name on one to see if it overrides the definition scope
            c = (Canvas)XamlReader.Load(@"
<Canvas
    xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
    xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" />
");
            c.Children.Add(new UserControl4());
            UserControl4 uc = new UserControl4();

            Assert.IsNotNull(uc.FindName("localNameForUserControl4"), "5");

            uc.Name = "thisOtherName";

            Assert.IsNull(uc.FindName("localNameForUserControl4"), "6");
            Assert.IsNotNull(uc.FindName("thisOtherName"), "7");

            // all that, but we still throw?
            Assert.Throws <ArgumentException> (() => c.Children.Add(new UserControl4()), "8");
        }
Example #2
0
		public void UserControlNamescope4 ()
		{
			UserControl4Container ucc = new UserControl4Container();

			// the name defined in the definition namescope for the usercontrol is visible
			Assert.IsNotNull (ucc.FindName("localNameForUserControl4"), "1");

			// the overridden name takes priority here
			Assert.IsNotNull (ucc.FindName("containerLocalName"), "2");

			// see what happens when we add two
			// UserControl4's with their default names
			// into the same canvas.
			Canvas c = (Canvas)XamlReader.Load (@"
<Canvas
    xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
    xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" />
");

			c.Children.Add (new UserControl4());
			Assert.Throws<ArgumentException> ( () => c.Children.Add (new UserControl4()), "3");

			// add them to a non-xamlreader created canvas
			Canvas c2 = new Canvas ();
			c2.Children.Add (new UserControl4());
			c2.Children.Add (new UserControl4());

			// and then add that canvas to a xamlreader created canvas.
			c = (Canvas)XamlReader.Load (@"
<Canvas
    xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
    xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" />
");

			Assert.Throws<ArgumentException> ( () => c.Children.Add (c2), "4");

			// add two of them but set the name on one to see if it overrides the definition scope
			c = (Canvas)XamlReader.Load (@"
<Canvas
    xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
    xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" />
");
			c.Children.Add (new UserControl4());
			UserControl4 uc = new UserControl4 ();

			Assert.IsNotNull (uc.FindName ("localNameForUserControl4"), "5");

			uc.Name = "thisOtherName";

			Assert.IsNull (uc.FindName ("localNameForUserControl4"), "6");
			Assert.IsNotNull (uc.FindName ("thisOtherName"), "7");

			// all that, but we still throw?
			Assert.Throws<ArgumentException> ( () => c.Children.Add (new UserControl4()), "8");
		}