本文整理汇总了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");
});
}
示例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;
}
示例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");
});
}
示例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;
}