当前位置: 首页>>代码示例>>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;未经允许,请勿转载。