FrameworkElement.LayoutTransform Property
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets or sets a graphics transformation that should apply to this element when layout is performed.
public:
property System::Windows::Media::Transform ^ LayoutTransform { System::Windows::Media::Transform ^ get(); void set(System::Windows::Media::Transform ^ value); };
public System.Windows.Media.Transform LayoutTransform { get; set; }
member this.LayoutTransform : System.Windows.Media.Transform with get, set
Public Property LayoutTransform As Transform
The transform this element should use. The default is Identity.
The following example shows how to apply a LayoutTransform to an element. The example creates an instance of Button and hosts it within a parent Grid. It also uses the LayoutTransform property to apply a RotateTransform to the Button.
Button^ btn2 = gcnew Button();
btn2->Background = Brushes::LightCoral;
btn2->Content = "RotateTransform";
btn2->LayoutTransform = gcnew RotateTransform(45, 25, 25);
Grid::SetRow(btn2, 0);
Grid::SetColumn(btn2, 1);
grid1->Children->Add(btn2);
Button btn2 = new Button();
btn2.Background = Brushes.LightCoral;
btn2.Content = "RotateTransform";
btn2.LayoutTransform = new RotateTransform(45, 25, 25);
Grid.SetRow(btn2, 0);
Grid.SetColumn(btn2, 1);
grid1.Children.Add(btn2);
Dim btn2 As New Button()
btn2.Background = Brushes.LightCoral
btn2.Content = "RotateTransform"
btn2.LayoutTransform = New RotateTransform(45, 25, 25)
Grid.SetRow(btn2, 0)
Grid.SetColumn(btn2, 1)
grid1.Children.Add(btn2)
<Button Grid.Row="0" Grid.Column="1" Background="LightCoral" Content="RotateTransform Applied">
<Button.LayoutTransform>
<RotateTransform CenterX="25" CenterY="25" Angle="45" />
</Button.LayoutTransform>
</Button>
In contrast to RenderTransform, LayoutTransform will affect results of layout.
Setting a transform provides powerful capabilities of scaling and rotating. However, LayoutTransform ignores TranslateTransform operations. This is because the layout system behavior for child elements of a FrameworkElement auto-corrects any offsets to the position of a scaled or rotated element into the layout and coordinate system of the parent element.
LayoutTransform can lead to poor application performance if you invoke it in a scenario that does not require a full pass by the layout system. When you apply a LayoutTransform to the Children collection of the Panel, it triggers a new pass by the layout system and forces all on-screen objects to be remeasured and rearranged. If you are updating the complete application user interface (UI), this functionality might be exactly what you need. However, if you do not need a full layout pass, use the RenderTransform property, which does not invoke the layout system, and therefore, is typically a better choice for this scenario.
Example scenarios where LayoutTransform would be useful include: rotating elements such as menu components from horizontal to vertical or vice versa, scaling elements (zooming in) on focus, providing editing behavior, etc.
Identifier field | LayoutTransformProperty |
Metadata properties set to true |
AffectsMeasure |
Product | Versions |
---|---|
.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 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: