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


C# Rectangle.TransformToVisual方法代碼示例

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


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

示例1: TransformToVisual_InVisualTree4

		public void TransformToVisual_InVisualTree4 ()
		{
			// Set explicit widths/heights on all elements so that the values of the MatrixTransform are predictable
			Rectangle a = new Rectangle { Width = 10, Height = 10, Fill = new SolidColorBrush (Colors.Red) };
			StackPanel panel = new StackPanel { Width = 100, Height = 100 };
			TestPanel.Width = 200;
			TestPanel.Height = 200;
			panel.Children.Add (a);
			CreateAsyncTest (panel, () => {
				GeneralTransform m = a.TransformToVisual (TestPanel);
				Assert.IsTrue (m is MatrixTransform, "#1");
				Assert.Matrix (((MatrixTransform) m).Matrix, 1, 0, 0, 1, 95, 50, "#2"); // Fails in Silverlight 3

				m = TestPanel.TransformToVisual (a);
				Assert.IsTrue (m is MatrixTransform, "#3");
				Assert.Matrix (((MatrixTransform) m).Matrix, 1, 0, 0, 1, -95, -50, "#4");
			});
		}
開發者ID:snorp,項目名稱:moon,代碼行數:18,代碼來源:UIElementTest.cs

示例2: CalculateActualLayout

        /// <summary>
        /// Calculate actual layout Rect of Rectangle relative to Viewbox.
        /// </summary>
        /// <param name="vb">Containing Viewbox.</param>
        /// <param name="r">Contained Rectangle.</param>
        /// <returns>Actual layout Rect of contained Rectangle relative to containing Viewbox.</returns>
        private static Rect CalculateActualLayout(Viewbox vb, Rectangle r)
        {
            Assert.AreEqual(VisualTreeHelper.GetChildrenCount(vb), 1, "Viewbox template changed!");
            Assert.IsInstanceOfType(VisualTreeHelper.GetChild(vb, 0), typeof(ContentPresenter), "Viewbox template changed!");

            ContentPresenter container = VisualTreeHelper.GetChild(vb, 0) as ContentPresenter;
            ScaleTransform scale = container.RenderTransform as ScaleTransform;
            Assert.IsNotNull(scale, "Viewbox implementation changed!");

            Point offset = r.TransformToVisual(vb).Transform(new Point(0, 0));
            offset = scale.Transform(offset);
            Rect actual = new Rect(offset.X, offset.Y, r.ActualWidth * scale.ScaleX, r.ActualHeight * scale.ScaleY);

            return actual;
        }
開發者ID:kvervo,項目名稱:HorizontalLoopingSelector,代碼行數:21,代碼來源:ViewboxTest.cs

示例3: TransformToVisual_InVisualTree3

		public void TransformToVisual_InVisualTree3 ()
		{
			Rectangle a = new Rectangle { Width = 10, Height = 10, Fill = new SolidColorBrush (Colors.Red) };
			Rectangle b = new Rectangle { Width = 10, Height = 10, Fill = new SolidColorBrush (Colors.Blue ) };
			StackPanel panel = new StackPanel ();
			panel.Children.Add (a);
			panel.Children.Add (b);
			CreateAsyncTest (panel, () => {
				GeneralTransform m = a.TransformToVisual (b);
				Assert.IsTrue (m is MatrixTransform, "#1");
				Assert.Matrix (((MatrixTransform) m).Matrix, 1, 0, 0, 1, 0, -10, "#2");
				
				m = b.TransformToVisual (a);
				Assert.IsTrue (m is MatrixTransform, "#3");
				Assert.Matrix (((MatrixTransform) m).Matrix, 1, 0, 0, 1, 0, 10, "#4");
			});
		}
開發者ID:snorp,項目名稱:moon,代碼行數:17,代碼來源:UIElementTest.cs

示例4: ClipImage

        void ClipImage()
        {
            RectangleGeometry geo = new RectangleGeometry();

            r = (Rectangle)(from c in LayoutRoot.Children where c.Opacity == 0.5 select c).First();
            GeneralTransform gt = r.TransformToVisual(LayoutRoot);
            Point p = gt.Transform(new Point(0, 0));
            geo.Rect = new Rect(p.X, p.Y, r.Width, r.Height);
            image1.Clip = geo;
            r.Visibility = System.Windows.Visibility.Collapsed;

            TranslateTransform t = new TranslateTransform();
            t.X = -p.X;
            t.Y = -p.Y;
            image1.RenderTransform = t;
        }
開發者ID:peepo3663,項目名稱:WindowsPhone8,代碼行數:16,代碼來源:MainPage.xaml.cs


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