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
属性值
声明呈现转换的值。 默认值是一个坐标为 (0,0) 的 Point。
示例
以下示例在代码中生成元素,应用 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 属性用法
<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 |
无 |