當前位置: 首頁>>代碼示例>>C#>>正文


C# Rectangle.FindName方法代碼示例

本文整理匯總了C#中System.Windows.Shapes.Rectangle.FindName方法的典型用法代碼示例。如果您正苦於以下問題:C# Rectangle.FindName方法的具體用法?C# Rectangle.FindName怎麽用?C# Rectangle.FindName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Windows.Shapes.Rectangle的用法示例。


在下文中一共展示了Rectangle.FindName方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: TemplatedControl

		public void TemplatedControl ()
		{
			TemplatedControl c = new TemplatedControl { Name = "Custom" };
			c.ApplyTemplate ();

			Rectangle Bob = new Rectangle { Name = "Bob" };
			Storyboard resourceSB = c.Resources ["ResourceSB"] as Storyboard;
			Storyboard templateSb = (Storyboard) c.GetTemplateChild ("TemplateSB");
			Grid grid = c.TemplateGrid;
			Rectangle rect = (Rectangle) grid.FindName ("Rect");
			Rectangle fakeGrid = new Rectangle { Name = "Grid" };

			c.TemplateGrid.Children.Add (Bob);
			testArea.Children.Add (c);

			Assert.IsNull (testArea.FindName ("LayoutRoot"), "LayoutRoot.FindName (\"LayoutRoot\")");
			Assert.IsTrue (testArea.FindName ("Custom") == c, "LayoutRoot.FindName (\"Custom\")");
			Assert.IsNull (testArea.FindName ("Grid"), "LayoutRoot.FindName (\"Grid\")");
			Assert.IsNull (testArea.FindName ("Bob"), "LayoutRoot.FindName (\"Bob\")");
			Assert.IsNull (testArea.FindName ("Rect"), "LayoutRoot.FindName (\"Rect\")");

			Assert.IsNull (c.FindName ("LayoutRoot"), "c.FindName (\"LayoutRoot\")");
			Assert.IsTrue (c.FindName ("Custom") == c, "c.FindName (\"Custom\")");
			Assert.IsNull (c.FindName ("Grid"), "c.FindName (\"Grid\")");
			Assert.IsTrue (c.FindName ("Bob") == Bob, "c.FindName (\"Bob\")");
			Assert.IsNull (c.FindName ("Rect"), "c.FindName (\"Rect\")");

			Assert.IsNull (grid.FindName ("LayoutRoot"), "grid.FindName (\"LayoutRoot\")");
			Assert.IsNull (grid.FindName ("Custom"), "grid.FindName (\"Custom\")");
			Assert.IsTrue (grid.FindName ("Grid") == grid, "grid.FindName (\"Grid\")");
			Assert.IsNull (grid.FindName ("Bob"), "grid.FindName (\"Bob\")");
			Assert.IsTrue (grid.FindName ("Rect") == rect, "grid.FindName (\"Rect\")");

			Assert.IsNull (Bob.FindName ("LayoutRoot"), "Bob.FindName (\"LayoutRoot\")");
			Assert.IsTrue (Bob.FindName ("Custom") == c, "Bob.FindName (\"Custom\")");
			Assert.IsNull (Bob.FindName ("Grid"), "Bob.FindName (\"Grid\")");
			Assert.IsTrue (Bob.FindName ("Bob") == Bob, "Bob.FindName (\"Bob\")");
			Assert.IsNull (Bob.FindName ("Rect"), "Bob.FindName (\"Rect\")");

			Assert.IsNull (rect.FindName ("LayoutRoot"), "rect.FindName (\"LayoutRoot\")");
			Assert.IsNull (rect.FindName ("Custom"), "rect.FindName (\"Custom\")");
			Assert.IsTrue (rect.FindName ("Grid") == c.TemplateGrid, "rect.FindName (\"Grid\")");
			Assert.IsNull (rect.FindName ("Bob"), "rect.FindName (\"Bob\")");
			Assert.IsTrue (rect.FindName ("Rect") == rect, "rect.FindName (\"Rect\")");
		}
開發者ID:dfr0,項目名稱:moon,代碼行數:45,代碼來源:Page.xaml.cs

示例2: ElementName_CanFindNonTemplateInTemplateSubtree

		public void ElementName_CanFindNonTemplateInTemplateSubtree ()
		{
			var c = (ContentControl) XamlReader.Load (@"
<ContentControl xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"">
	<ContentControl.Template>
		<ControlTemplate>
			<Grid />
		</ControlTemplate>
	</ContentControl.Template>
</ContentControl>");
			c.ApplyTemplate ();

			var grid = (Grid) VisualTreeHelper.GetChild (c, 0);
			var a = new Rectangle { Name = "A" };
			var b = new Rectangle { Name = "B" };
			grid.Children.Add (a);
			grid.Children.Add (b);
			Assert.AreSame (b, a.FindName ("B"), "#1");
			Assert.IsNull (grid.FindName ("B"), "#2");
			Assert.AreSame (b, c.FindName ("B"), "#3");
		}
開發者ID:dfr0,項目名稱:moon,代碼行數:21,代碼來源:BindingTest.cs


注:本文中的System.Windows.Shapes.Rectangle.FindName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。