UIElement.RenderTransformOrigin 屬性

定義

取得或設定 RenderTransform (相對於項目邊界) 宣告任何可能呈現轉換的中心點。 這是相依性屬性。

C#
public System.Windows.Point RenderTransformOrigin { get; set; }

屬性值

宣告呈現轉換的值。 預設值是 Point 且座標為 (0,0)。

範例

下列範例會在程式碼中建置專案、套用 RenderTransformOrigin ,然後套用 RenderTransform

C#
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;
}

備註

RenderTransformOrigin 結構值的一些非標準用法 Point ,也就是說, Point 不代表座標系統中的絕對位置。 相反地,介於 0 和 1 之間的值會解譯為每個 x,y 軸中目前元素範圍的因數。 例如, (0.5,0.5) 會導致轉譯轉換置中于元素上,或 (1,1) 會將轉譯轉換放在元素的右下角。 NaN 不是可接受的值。

也會接受超過 0 和 1 的值,並會產生更多非傳統轉換效果。 例如,如果您將 設定 RenderTransformOrigin 為 (5,5) ,然後套用 RotateTransform ,則旋轉點會非常超出元素本身的界限。 轉換會在源自右下角的大型圓形中繞著元素旋轉。 原點可能位於其父元素內的某處,而且可能不在框架或檢視中。 負點值類似,這些值會超出左上方界限。

轉譯轉換不會影響版面配置,通常用來建立動畫效果或將暫存效果套用至元素。

XAML Attribute Usage

<object RenderTransformOrigin="xOrigin, yOrigin"/>  

XAML 屬性項目用法

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

XAML 值

xOrigin
水準原點因數。 這通常會指定為介於 0 到 1 之間的值。 請參閱<備註>。

yOrigin
垂直原點因數。 這通常會指定為介於 0 到 1 之間的值。 請參閱<備註>。

相依性屬性資訊

識別碼欄位 RenderTransformOriginProperty
設定為 的中繼資料屬性 true

適用於

產品 版本
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

另請參閱