UIElement.RenderTransformOrigin 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定 RenderTransform (相對於項目邊界) 宣告任何可能呈現轉換的中心點。 這是相依性屬性。
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
屬性值
宣告呈現轉換的值。 預設值是 Point 且座標為 (0,0)。
範例
下列範例會在程式碼中建置專案、套用 RenderTransformOrigin ,然後套用 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
備註
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 |
無 |