UIElement.RenderTransformOrigin UIElement.RenderTransformOrigin UIElement.RenderTransformOrigin UIElement.RenderTransformOrigin Property

定义

获取或设置由 RenderTransform 声明的任何可能呈现转换的中心点,相对于元素的边界。Gets or sets the center point of any possible render transform declared by RenderTransform, relative to the bounds of the element. 这是依赖项属性。This is a dependency property.

public:
 property System::Windows::Point RenderTransformOrigin { System::Windows::Point get(); void set(System::Windows::Point value); };
public System.Windows.Point RenderTransformOrigin { get; set; }
member this.RenderTransformOrigin : System.Windows.Point with get, set
Public Property RenderTransformOrigin As Point

属性值

声明呈现转换的值。The value that declares the render transform. 默认值是一个坐标为 (0,0) 的 PointThe default value is a Point with coordinates (0,0).

示例

下面的示例在代码中生成元素, 应用RenderTransformOrigin, 然后RenderTransform应用。The following example builds up elements in code, applies a RenderTransformOrigin, and then applies a RenderTransform.

public RotateAboutCenterExample()
{
    this.WindowTitle = "Rotate About Center Example";
    NameScope.SetNameScope(this, new NameScope());
    StackPanel myStackPanel = new StackPanel();
    myStackPanel.Margin = new Thickness(50);

    Button myButton = new Button();
    myButton.Name = "myRenderTransformButton";
    this.RegisterName(myButton.Name,myButton);
    myButton.RenderTransformOrigin = new Point(0.5,0.5);
    myButton.HorizontalAlignment = HorizontalAlignment.Left;
    myButton.Content = "Hello World";


    RotateTransform myRotateTransform = new RotateTransform(0);
    myButton.RenderTransform = myRotateTransform;
    this.RegisterName("MyAnimatedTransform",myRotateTransform);

    myStackPanel.Children.Add(myButton);

    //
    // Creates an animation that accelerates through 40% of its duration and
    //      decelerates through the 60% of its duration.
    //
    DoubleAnimation myRotateAboutCenterAnimation = new DoubleAnimation();
    Storyboard.SetTargetName(myRotateAboutCenterAnimation,"MyAnimatedTransform");
    Storyboard.SetTargetProperty(myRotateAboutCenterAnimation,new PropertyPath(RotateTransform.AngleProperty));
    myRotateAboutCenterAnimation.From = 0.0;
    myRotateAboutCenterAnimation.To = 360;
    myRotateAboutCenterAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(1000));

    // Create a Storyboard to contain the animations and
    // add the animations to the Storyboard.
    Storyboard myStoryboard = new Storyboard();
    myStoryboard.Children.Add(myRotateAboutCenterAnimation);

    // Create an EventTrigger and a BeginStoryboard action to
    // start the storyboard.
    EventTrigger myEventTrigger = new EventTrigger();
    myEventTrigger.RoutedEvent = Button.ClickEvent;
    myEventTrigger.SourceName = myButton.Name;
    BeginStoryboard myBeginStoryboard = new BeginStoryboard();
    myBeginStoryboard.Storyboard = myStoryboard;
    myEventTrigger.Actions.Add(myBeginStoryboard);
    myStackPanel.Triggers.Add(myEventTrigger);

    this.Content = myStackPanel;
}
Public Sub New()
	Me.WindowTitle = "Rotate About Center Example"
	NameScope.SetNameScope(Me, New NameScope())
	Dim myStackPanel As New StackPanel()
	myStackPanel.Margin = New Thickness(50)

	Dim myButton As New Button()
	myButton.Name = "myRenderTransformButton"
	Me.RegisterName(myButton.Name,myButton)
	myButton.RenderTransformOrigin = New Point(0.5,0.5)
	myButton.HorizontalAlignment = HorizontalAlignment.Left
	myButton.Content = "Hello World"


	Dim myRotateTransform As New RotateTransform(0)
	myButton.RenderTransform = myRotateTransform
	Me.RegisterName("MyAnimatedTransform",myRotateTransform)

	myStackPanel.Children.Add(myButton)

	'
	' Creates an animation that accelerates through 40% of its duration and
	'      decelerates through the 60% of its duration.
	'
	Dim myRotateAboutCenterAnimation As New DoubleAnimation()
	Storyboard.SetTargetName(myRotateAboutCenterAnimation,"MyAnimatedTransform")
	Storyboard.SetTargetProperty(myRotateAboutCenterAnimation,New PropertyPath(RotateTransform.AngleProperty))
	myRotateAboutCenterAnimation.From = 0.0
	myRotateAboutCenterAnimation.To = 360
	myRotateAboutCenterAnimation.Duration = New Duration(TimeSpan.FromMilliseconds(1000))

	' Create a Storyboard to contain the animations and
	' add the animations to the Storyboard.
	Dim myStoryboard As New Storyboard()
	myStoryboard.Children.Add(myRotateAboutCenterAnimation)

	' Create an EventTrigger and a BeginStoryboard action to
	' start the storyboard.
	Dim myEventTrigger As New EventTrigger()
	myEventTrigger.RoutedEvent = Button.ClickEvent
	myEventTrigger.SourceName = myButton.Name
	Dim myBeginStoryboard As New BeginStoryboard()
	myBeginStoryboard.Storyboard = myStoryboard
	myEventTrigger.Actions.Add(myBeginStoryboard)
	myStackPanel.Triggers.Add(myEventTrigger)

	Me.Content = myStackPanel
End Sub

注解

RenderTransformOriginPoint结构值的使用有点非标准, 因为在Point坐标系统中不表示绝对位置。RenderTransformOrigin has a somewhat nonstandard use of the Point structure value, in that the Point does not represent an absolute location in a coordinate system. 相反, 介于0和1之间的值被解释为每个 x, y 轴中当前元素的范围的因子。Instead, values between 0 and 1 are interpreted as a factor for the range of the current element in each x,y axis. 例如, (0.5, 0.5) 将导致在元素上居中呈现转换, 或者 (1, 1) 将呈现转换放置在元素的右下角。For example, (0.5,0.5) will cause the render transform to be centered on the element, or (1,1) would place the render transform at the bottom right corner of the element. NaN不是接受的值。NaN is not an accepted value.

还将接受0和1之外的值, 并将导致更非常规的转换效果。Values beyond 0 and 1 are also accepted, and will result in more unconventional transform effects. 例如, 如果将设置RenderTransformOrigin为 (5, 5), 然后RotateTransform应用, 则旋转点将在元素本身的边界之外。For instance, if you set RenderTransformOrigin to be (5,5), and then apply a RotateTransform, the rotation point will be well outside the bounds of the element itself. 该转换将使元素围绕在右下方的大圆中旋转。The transform will spin your element around in a big circle that originates beyond bottom right. 原点可能位于其父元素内的某个位置, 可能可能会超出框架或视图。The origin might be somewhere inside its parent element and could possibly be possibly out of frame or view. 负点值类似, 它们将超出左上边界。Negative point values are similar, these will go beyond the top left bounds.

呈现转换不影响布局, 通常用于对元素进行动画或应用临时效果。Render transforms do not affect layout, and are typically used to animate or apply a temporary effect to an element.

XAML 属性用法XAML Attribute Usage

<object RenderTransformOrigin="xOrigin, yOrigin"/>  

XAML 属性元素用法XAML Property Element Usage

<object>  
  <object.RenderTransformOrigin>  
    <Point X=" xOrigin " Y=" yOrigin "/>  
  </object.RenderTransformOrigin>  
</object>  

XAML 值XAML Values

xOriginxOrigin
水平原点系数。The horizontal origin factor. 通常将此值指定为0和1之间的值。This is typically given as a value between 0 and 1. 请参阅“备注”。See Remarks.

yOriginyOrigin
垂直原点系数。The vertical origin factor. 通常将此值指定为0和1之间的值。This is typically given as a value between 0 and 1. 请参阅“备注”。See Remarks.

依赖项属性信息Dependency Property Information

标识符字段Identifier field RenderTransformOriginProperty
元数据属性设置为trueMetadata properties set to true NoneNone

适用于

另请参阅