我尝试旋转 aBorder并MainWindow根据旋转占用的新空间更改他的大小Border。我已经设置SizeToContent="WidthAndHeight",但是当我旋转边框时窗口大小不会改变。
我是否需要以编程方式为 MainWindow 设置WidthandHeight或者这可以通过其他方式更改 xaml 代码来实现?
我的xml代码:
<Window x:Class="MyClass.MainWindow"
WindowStyle="None" AllowsTransparency='True'
Topmost='False' Background="Transparent" ShowInTaskbar='False'
SizeToContent="WidthAndHeight" WindowStartupLocation="Manual">
<Border Name="MyBorder"
BorderBrush="Transparent"
Background="Transparent"
HorizontalAlignment="Left"
VerticalAlignment="Top"
RenderTransformOrigin="0.5,0.5">
</Border>
</Windows>
我的c#代码Window_KeyDown:
# RotateTransform rt = new RotateTransform()在类级别声明。
if (e.Key == Key.I)
{
if (rt.Angle + 1 < 360)
{
rt.Angle += 1;
}
else
{
rt.Angle = 0;
}
MyBorder.RenderTransform = rt;
}