FrameworkElement.LayoutTransform 屬性

定義

取得或設定應在執行配置時,套用在這個項目圖形轉換。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. 預設為 IdentityThe default is Identity.

範例

下列範例顯示如何將 LayoutTransform 套用至專案。The following example shows how to apply a LayoutTransform to an element. 此範例會建立 Button 的實例,並將它裝載在父 Grid中。The example creates an instance of Button and hosts it within a parent Grid. 它也會使用 LayoutTransform 屬性,將 RotateTransform 套用至 ButtonIt 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>

備註

相對於 RenderTransformLayoutTransform 會影響版面配置的結果。In contrast to RenderTransform, LayoutTransform will affect results of layout.

設定轉換可提供調整和旋轉的強大功能。Setting a transform provides powerful capabilities of scaling and rotating. 不過,LayoutTransform 會忽略 TranslateTransform 作業。However, LayoutTransform ignores TranslateTransform operations. 這是因為 FrameworkElement 之子專案的版面配置系統行為會自動將縮放或旋轉專案位置的任何位移,更正為父元素的版面配置和座標系統。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 可能會導致應用程式效能不佳。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. 當您將 LayoutTransform 套用至 PanelChildren 集合時,它會觸發配置系統的新傳遞,並強制重新測量和重新排列所有的螢幕物件。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. 如果您要更新完整的應用程式 使用者介面 (UI)user interface (UI),此功能可能正是您所需的。If you are updating the complete application 使用者介面 (UI)user interface (UI), this functionality might be exactly what you need. 不過,如果您不需要完整的版面配置,請使用不會叫用版面配置系統的 RenderTransform 屬性,因此通常是更適合此案例的選擇。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.

LayoutTransform 有用的範例案例包括:將專案(例如功能表元件)從水準重設為垂直,或反之亦然、縮放元素(放大)以聚焦、提供編輯行為等等。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.

相依性屬性資訊Dependency Property Information

識別碼欄位Identifier field LayoutTransformProperty
設定為 true 的中繼資料屬性Metadata properties set to true AffectsMeasure

適用於

另請參閱