Windows 10使用初始大小创建新窗口

时间:2015-07-21 17:24:33

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

我正在尝试在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);
                          });

1 个答案:

答案 0 :(得分:1)

显示窗口后调整窗口大小。

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

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