以编程方式调整 WPF 应用程序主窗口的大小

发布于 2024-09-27 18:33:41 字数 465 浏览 2 评论 0原文

我的应用程序在触摸屏上运行,并且有一个透明的主窗口,因此调整大小的唯一方法是使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

春风十里 2024-10-04 18:33:41

上面的代码语法是正确的,这意味着 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文