以编程方式调整 WPF 应用程序主窗口的大小
我的应用程序在触摸屏上运行,并且有一个透明的主窗口,因此调整大小的唯一方法是使用grip,但在触摸屏上很难做到。我想知道是否有办法以编程方式增加大小。
我尝试过使用自定义命令,但窗口仅增加了少量。这是我的命令的代码:
private const int sizeIncreaseThreshold = 50;
private double aspectRatio = 2.45;
private void IncreaseSizeExecuted(object sender, ExecutedRoutedEventArgs e)
{
this.Width = this.Width + sizeIncreaseThreshold * aspectRatio;
this.Height = this.Height + sizeIncreaseThreshold;
e.Handled = true;
}
My application is running on a touch-screen and it has a transparent main window, so only way to resize is using grip, but on the touch-screen it is quite hard to do. I wonder if there is a way to increase the size programmatically.
I have tried using custom commands but the window increases only by a small amount. Here is the code for my command:
private const int sizeIncreaseThreshold = 50;
private double aspectRatio = 2.45;
private void IncreaseSizeExecuted(object sender, ExecutedRoutedEventArgs e)
{
this.Width = this.Width + sizeIncreaseThreshold * aspectRatio;
this.Height = this.Height + sizeIncreaseThreshold;
e.Handled = true;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
上面的代码语法是正确的,这意味着 sizeIncreaseThreshold 值必须很小(对于高度),或更可能的是,您的宽高比是小于 1 的值。
换句话说,如果您的宽高比是 0.5,并且 sizeIncreaseThreshold是 10,每次执行该命令时,您将把高度增加 10,但宽度增加 5。
The code syntax above is correct, which means that the sizeIncreaseThreshold value must be small (for the height), or more likely, your aspect ratio is a value less than 1.
In other words, if your aspect ratio is 0.5, and the sizeIncreaseThreshold is 10, you are going to increase the Height by 10, but the width by 5, each time the command is executed.