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.

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

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 .

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

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

Prodotto Versioni
.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

Vedi anche