UIElement.RenderTransformOrigin Proprietà

Definizione

Ottiene o imposta il punto centrale di qualsiasi trasformazione di rendering possibile dichiarata da RenderTransform, rispetto ai limiti dell'elemento. Si tratta di una proprietà di dipendenza.

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

Valore della proprietà

Valore che dichiara la trasformazione di rendering. Il valore predefinito è un Point con le coordinate (0,0).

Esempio

Nell'esempio seguente vengono compilati elementi nel codice, viene applicato un RenderTransformOriginoggetto e quindi viene applicato un RenderTransformoggetto .

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

Commenti

RenderTransformOrigin ha un uso non standard del valore della Point struttura, in quanto Point non rappresenta una posizione assoluta in un sistema di coordinate. I valori compresi tra 0 e 1 vengono invece interpretati come fattore per l'intervallo dell'elemento corrente in ogni asse x,y. Ad esempio, (0.5.5) la trasformazione di rendering verrà centrata sull'elemento oppure (1,1) posiziona la trasformazione di rendering nell'angolo inferiore destro dell'elemento. NaN non è un valore accettato.

I valori oltre 0 e 1 sono accettati anche e comportano effetti di trasformazione più non convenzionali. Ad esempio, se si imposta RenderTransformOrigin su (5,5) e quindi si applica un RotateTransform, il punto di rotazione sarà ben esterno ai limiti dell'elemento stesso. La trasformazione spinerà l'elemento intorno a un cerchio grande che si origina oltre il basso destro. L'origine potrebbe essere da qualche parte all'interno dell'elemento padre e potrebbe eventualmente essere fuori cornice o vista. I valori dei punti negativi sono simili, questi andranno oltre i limiti in alto a sinistra.

Le trasformazioni di rendering non influiscono sul layout e vengono in genere usate per animare o applicare un effetto temporaneo a un elemento.

Uso della sintassi XAML per gli attributi

<object RenderTransformOrigin="xOrigin, yOrigin"/>  

Utilizzo della sintassi XAML per elementi proprietà

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

Valori XAML

xOrigin
Fattore di origine orizzontale. Questo valore viene in genere assegnato come valore compreso tra 0 e 1. Vedere la sezione Osservazioni.

yOrigin
Fattore di origine verticale. Questo valore viene in genere assegnato come valore compreso tra 0 e 1. Vedere la sezione Osservazioni.

Informazioni proprietà di dipendenza

Campo Identificatore RenderTransformOriginProperty
Proprietà dei metadati impostate su true Nessuno

Si applica a

Vedi anche