![](/img/trans.png)
[英]How to rotate an image within a StackPanel or Grid in Silverlight
[英]rotate Canvas within a Grid
我可以使用LayoutTransform精細旋轉畫布。 但是拐角超出了網格的寬度或高度。 如何旋轉畫布並調整其大小以將其保留在Grid中。 這是我的旋轉方式:-
private void btnRotate_Click(object sender, RoutedEventArgs e)
{
if (RotationAngle == 360)
{
RotationAngle = 0;
}
RotationAngle = RotationAngle + 1;
RotateTransform rotateTransform = new RotateTransform();
rotateTransform.Angle = RotationAngle;
TransformGroup transformGroup = new TransformGroup();
transformGroup.Children.Add(rotateTransform);
rotateTransform.CenterX = 0.5;
rotateTransform.CenterY = 0.5;
cnvsYardMap.LayoutTransform = transformGroup;
}
謝謝。
如果Grid
無法容納其子Canvas
的新大小,則它會超出范圍。
因此,如果您有類似以下內容:
<Grid Height="200">
<Canvas x:Name="blah"
Width="280"
Height="150"
Background="Tomato" />
</Grid>
並且您應用LayoutTransform
,這確實會溢出。
對於您要嘗試的操作,可以將Canvas
包裝在ViewBox中 。 所以像這樣:
<Grid Height="200">
<Viewbox>
<Canvas x:Name="blah"
Width="280"
Height="150"
Background="Tomato" />
</Viewbox>
</Grid>
現在,應用相同的變換將“出現”以縮小Canvas
大小以使其適合父Grid
。 請注意, Viewbox
縮放子級而不是調整子級的大小,因此這只是一種視覺效果。 Canvas
的Width
和Height
仍將保持轉換之前的原始狀態。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.