UIElement.RenderTransformOrigin Proprietà

Definizione

Ottiene o imposta il punto centrale di qualsiasi possibile trasformazione di rendering 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 oggetto con coordinate (0,0).

Esempio

Nell'esempio seguente vengono compilati elementi nel codice, viene applicato un RenderTransformOriginoggetto e quindi viene applicato un oggetto 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

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,0,5) causerà il centro della trasformazione di rendering sull'elemento oppure (1,1) posiziona la trasformazione di rendering nell'angolo inferiore destro dell'elemento. NaN non è un valore accettato.

Anche i valori superiori a 0 e 1 vengono accettati e comportano effetti di trasformazione 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 farà ruotare l'elemento in un cerchio grande che ha origine oltre il basso a destra. L'origine potrebbe trovarsi in un punto qualsiasi all'interno dell'elemento padre e potrebbe essere probabilmente fuori cornice o vista. I valori dei punti negativi sono simili, che andranno oltre i limiti superiore sinistro.

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

Utilizzo degli attributi XAML

<object RenderTransformOrigin="xOrigin, yOrigin"/>

Utilizzo dell'elemento della proprietà XAML

<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 sulle proprietà di dipendenza

Item Value
Campo Identificatore RenderTransformOriginProperty
Proprietà dei metadati impostate su true Nessuno

Si applica a

Vedi anche