Example #1
0
		public void BrushWithTwoParents_TwoSubtrees_SetOneFirst()
		{
			var brush = new SolidColorBrush();
			brush.SetValue(FrameworkElement.NameProperty, "Test");

			var first = (Canvas)XamlReader.Load(@"<Canvas xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" />");
			var second = (Canvas)XamlReader.Load(@"<Canvas xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" />");

			first.Children.Add(new Canvas { Background = brush });
			second.Children.Add(new Canvas { Background = brush });

			Assert.AreSame(brush, first.FindName("Test"), "#1");
			Assert.IsNull(second.FindName("Test"), "#2");
		}
Example #2
0
		public void UseTwice()
		{
			string name = "SuperSecretBrush";
			Brush b1 = new SolidColorBrush();
			b1.SetValue(FrameworkElement.NameProperty, name);

			var g1 = new Grid { Name = "g1", Background = b1 };
			var g2 = new Grid { Name = "g2", Background = b1 };

			TestPanel.Children.Add(g1);
			Assert.IsNull(TestPanel.FindName(name), "#1");

			TestPanel.Children.Add(g2);
			Assert.IsNull(TestPanel.FindName(name), "#2");
		}
Example #3
0
		public void UseTwice_ThenOnce()
		{
			string name = "SuperSecretBrush";
			Brush brush = new SolidColorBrush();
			brush.SetValue(FrameworkElement.NameProperty, name);

			var g1 = new Grid { Name = "g1", Background = brush };
			var g2 = new Grid { Name = "g2", Background = brush };

			TestPanel.Children.Add(g1);
			Assert.IsNull(TestPanel.FindName(name), "#1");

			g2.Background = null;
			Assert.IsNull(TestPanel.FindName(name), "#2");

			TestPanel.Children.Clear();
			TestPanel.Children.Add(g1);
			Assert.AreSame(brush, TestPanel.FindName(name), "#3");
		}
Example #4
0
		public void BrushWithTwoParents_UnregisterWrongObject()
		{
			// Create two brushes with the same name. Put one of them in both
			// textboxes and the other just in the second textbox. See if clearing
			// the first brush in the second textbox will unregister the name of the
			// second brush from the second textbox.
			var brush = new SolidColorBrush();
			brush.SetValue(FrameworkElement.NameProperty, "Test");
			
			var secondBrush = new SolidColorBrush();
			secondBrush.SetValue(FrameworkElement.NameProperty, "Test");

			var first = (TextBox)XamlReader.Load(@"<TextBox xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" />");
			var second = (TextBox)XamlReader.Load(@"<TextBox xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" />");

			first.Foreground = brush;
			second.Foreground = brush;

			second.Background = secondBrush;
			second.Foreground = null;

			Assert.AreSame(secondBrush, second.FindName("Test"), "#1");
		}
Example #5
0
		public void BrushWithThreeParents_ComplexParenting_AlternateNull()
		{
			var brush = new SolidColorBrush();
			brush.SetValue(FrameworkElement.NameProperty, "Test");

			var first = (TextBox)XamlReader.Load(@"<TextBox xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" />");
			var second = (TextBox)XamlReader.Load(@"<TextBox xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" />");
			var third = (TextBox)XamlReader.Load(@"<TextBox xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" />");
			var fourth = (TextBox)XamlReader.Load(@"<TextBox xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" />");

			first.Foreground = brush;
			Assert.AreSame(brush, first.FindName("Test"), "#1a");
			Assert.IsNull(second.FindName("Test"), "#2a");
			Assert.IsNull(third.FindName("Test"), "#3a");
			Assert.IsNull(fourth.FindName("Test"), "#4a");

			second.Foreground = brush;
			first.Foreground = null;
			Assert.AreSame(brush, first.FindName("Test"), "#1b");
			Assert.IsNull(second.FindName("Test"), "#2b");
			Assert.IsNull(third.FindName("Test"), "#3b");
			Assert.IsNull(fourth.FindName("Test"), "#4b");

			third.Foreground = brush;
			second.Foreground = null;
			Assert.AreSame(brush, first.FindName("Test"), "#1c");
			Assert.IsNull(second.FindName("Test"), "#2c");
			Assert.IsNull(third.FindName("Test"), "#3c");
			Assert.IsNull(fourth.FindName("Test"), "#4c");

			fourth.Foreground = brush;
			third.Foreground = null;
			Assert.AreSame(brush, first.FindName("Test"), "#5a");
			Assert.IsNull(second.FindName("Test"), "#5b");
			Assert.IsNull(third.FindName("Test"), "#5c");
			Assert.IsNull(fourth.FindName("Test"), "#5d");

			fourth.Foreground = null;
			Assert.AreSame(brush, first.FindName("Test"), "#6a");
			Assert.IsNull(second.FindName("Test"), "#6b");
			Assert.IsNull(third.FindName("Test"), "#6c");
			Assert.IsNull(fourth.FindName("Test"), "#6d");
		}
Example #6
0
		public void BrushWithThreeParents_NullInReverseOrder()
		{
			var brush = new SolidColorBrush();
			brush.SetValue(FrameworkElement.NameProperty, "Test");

			var first = (TextBox)XamlReader.Load(@"<TextBox xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" />");
			var second = (TextBox)XamlReader.Load(@"<TextBox xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" />");
			var third = (TextBox)XamlReader.Load(@"<TextBox xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" />");

			first.Foreground = brush;
			second.Foreground = brush;
			third.Foreground = brush;

			third.Foreground = null;
			second.Foreground = null;
			first.Foreground = null;

			Assert.IsNull(first.FindName("Test"), "#1");
			Assert.IsNull(second.FindName("Test"), "#1");
			Assert.IsNull(third.FindName("Test"), "#1");
		}
Example #7
0
		public void BrushWithThreeParents_NullAll_ThenPutInNewNamescope()
		{
			// Create two TextBlocks with unique namescopes and add the same brush to  both.
			// Then null the properties and add the brush to a third namescope to see if it
			// is registered there.
			var brush = new SolidColorBrush();
			brush.SetValue(FrameworkElement.NameProperty, "Test");

			var first = (TextBox)XamlReader.Load(@"<TextBox xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" />");
			var second = (TextBox)XamlReader.Load(@"<TextBox xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" />");
			var third = (TextBox)XamlReader.Load(@"<TextBox xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" />");
			var fourth = (TextBox)XamlReader.Load(@"<TextBox xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" />");

			first.Foreground = null;
			second.Foreground = null;
			third.Foreground = null;
			fourth.Foreground = null;

			first.Foreground = brush;
			second.Foreground = brush;
			third.Foreground = brush;

			first.Foreground = null;
			second.Foreground = null;
			third.Foreground = null;

			fourth.Foreground = brush;
			Assert.AreSame(brush, fourth.FindName("Test"), "#1");
		}
Example #8
0
		public void BrushWithTwoParents_NullBoth_NamescopeClash()
		{
			// Create two TextBlocks with unique namescopes and add the same brush to  both
			// If we then clear the two Foregrounds by setting them to null, the name is never
			// unregistered from the first namescope so if we try to reuse the name we blow up.
			var first = (TextBox)XamlReader.Load(@"<TextBox xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" />");
			var second = (TextBox)XamlReader.Load(@"<TextBox xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" />");

			var brush = new SolidColorBrush();
			brush.SetValue(FrameworkElement.NameProperty, "Test");
			first.Foreground = brush;
			second.Foreground = brush;

			first.Foreground = null;
			second.Foreground = null;

			brush = new SolidColorBrush();
			brush.SetValue(FrameworkElement.NameProperty, "Test");

			Assert.Throws<ArgumentException>(() => first.Foreground = brush, "#1");
		}
Example #9
0
		public void BrushWithTwoParents_NullBoth()
		{
			// Create two TextBlocks with unique namescopes and add the same brush to  both
			// By setting the Foreground properties to null, the brush is still in the namescope
			var first = (TextBox)XamlReader.Load(@"<TextBox xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" />");
			var second = (TextBox)XamlReader.Load(@"<TextBox xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" />");

			var brush = new SolidColorBrush();
			brush.SetValue(FrameworkElement.NameProperty, "Test");
			first.Foreground = brush;
			second.Foreground = brush;

			first.Foreground = null;
			second.Foreground = null;
			Assert.AreSame(brush, first.FindName("Test"), "#1");
			Assert.IsNull(second.FindName("Test"), "#2");
		}
Example #10
0
		public void BrushWithTwoParents_NullSecond_ThenPutInNewNamescope()
		{
			// Create two TextBlocks with unique namescopes and add the same brush to  both
			var first = (TextBox)XamlReader.Load(@"<TextBox xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" />");
			var second = (TextBox)XamlReader.Load(@"<TextBox xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" />");

			var brush = new SolidColorBrush();
			brush.SetValue(FrameworkElement.NameProperty, "Test");
			first.Foreground = brush;
			second.Foreground = brush;

			second.Foreground = null;

			var third = (TextBox)XamlReader.Load(@"<TextBox xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" />");
			third.Foreground = brush;
			Assert.IsNull(third.FindName("Test"), "#1");
		}