【发布时间】:2012-06-11 19:07:57
【问题描述】:
我尝试旋转Border 并让MainWindow 根据Border 旋转占用的新空间更改其大小。
我设置了SizeToContent="WidthAndHeight",但是当我旋转边框时窗口大小没有改变。
我是否需要以编程方式为 MainWindow 设置 Width 和 Height,或者这可以通过其他方式更改 xaml 代码来实现?
我的 xaml 代码:
<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>
我在Window_KeyDown 上的c# 代码:
# RotateTransform rt = new RotateTransform() 在类级别声明。
if (e.Key == Key.I)
{
if (rt.Angle + 1 < 360)
{
rt.Angle += 1;
}
else
{
rt.Angle = 0;
}
MyBorder.RenderTransform = rt;
}
【问题讨论】: