【问题标题】:Windows 10 Creating new window with initial sizeWindows 10 创建具有初始大小的新窗口
【发布时间】:2015-10-11 07:11:28
【问题描述】:

我正在尝试在我的 Windows 10 应用程序中创建一个新窗口,但我希望能够为创建的窗口指定初始大小。

到目前为止,我一直在尝试,但没有运气 -

            var currentAppView = ApplicationView.GetForCurrentView();

            var newCoreAppView = CoreApplication.CreateNewView();
            await newCoreAppView.Dispatcher.RunAsync(
                          CoreDispatcherPriority.Normal,
                          async () =>
                          {
                              var newWindow = Window.Current;
                              var newAppView = ApplicationView.GetForCurrentView();
                              newAppView.SetPreferredMinSize(new Size(1, 1));
                              newAppView.TryResizeView(new Size(300, 300));
                              newAppView.Title = "New small window";

                              var frame = new Frame();
                              frame.Navigate(typeof(NewPage), null);
                              newWindow.Content = frame;
                              newWindow.Activate();

                              await ApplicationViewSwitcher.TryShowAsStandaloneAsync(
                                    newAppView.Id,
                                    ViewSizePreference.UseMinimum,
                                    currentAppView.Id,
                                    ViewSizePreference.UseMinimum);
                          });

【问题讨论】:

  • 结果如何?
  • 当前创建的窗口大小与原始窗口相同。这里的目标是创建大小为 300x300 的窗口。
  • 看看this是否回答了你的问题。

标签: c# windows windows-runtime windows-10


【解决方案1】:

显示后调整窗口大小。

await ApplicationViewSwitcher.TryShowAsStandaloneAsync(
    newAppView.Id,
    ViewSizePreference.UseMinimum,
    currentAppView.Id,
    ViewSizePreference.UseMinimum);

newAppView.TryResizeView(new Size(300, 300));

【讨论】:

  • 虽然这确实有效,但有时它会在调整大小之前以相同大小显示初始屏幕,这可能会令人不快。不幸的是,这也可能导致应用以较小的尺寸从头开始重新打开
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-18
  • 2015-11-21
  • 2016-06-02
  • 2020-09-19
相关资源
最近更新 更多