在下面的代码中,我无法修改ViewSizePreference选项并使子节点小于父节点。我正在从一个页面弹出一个窗口。那部分工作正常。但是,两个窗口的大小完全相同。
private async void Test_Click(object sender,RoutedEventArgs e){
var currentAV = ApplicationView.GetForCurrentView();
var newAV = CoreApplication.CreateNewView();
await newAV.Dispatcher.RunAsync(
CoreDispatcherPriority.Normal,
async () =>
{
var newWindow = Window.Current;
var newAppView = ApplicationView.GetForCurrentView();
newAppView.Title = "New window";
var frame = new Frame();
frame.Navigate(typeof(MainPage), null);
newWindow.Content = frame;
newWindow.Activate();
await ApplicationViewSwitcher.TryShowAsStandaloneAsync(
newAppView.Id,
ViewSizePreference.UseMinimum,
currentAV.Id,
ViewSizePreference.UseMinimum);
});
}
答案 0 :(得分:1)
但是,两个窗口的大小完全相同。
是的,我刚发现同样的问题,而且我已经报告了这个问题。一旦我得到这个问题的答复,我会在这里发帖。
到目前为止,我们可以使用解决方法来解决此问题,因为您希望扩展尺寸小于主窗口的新窗口,您可以使用ApplicationView.TryResizeView | tryResizeView method以编程方式设置新窗口的大小。
例如:
private async void Test_Click(object sender, RoutedEventArgs e)
{
var currentAV = ApplicationView.GetForCurrentView();
//get the bounds of current window.
var rect = Window.Current.Bounds;
var newAV = CoreApplication.CreateNewView();
await newAV.Dispatcher.RunAsync(
CoreDispatcherPriority.Normal,
async () =>
{
var newWindow = Window.Current;
var newAppView = ApplicationView.GetForCurrentView();
newAppView.Title = "New window";
var frame = new Frame();
//send current window's size as parameter.
frame.Navigate(typeof(MainPage), rect.Width.ToString() + ":" + rect.Height.ToString());
newWindow.Content = frame;
newWindow.Activate();
await ApplicationViewSwitcher.TryShowAsStandaloneAsync(
newAppView.Id,
ViewSizePreference.UseHalf,
currentAV.Id,
ViewSizePreference.UseHalf);
});
}
然后使用OnNavigatedTo
方法和Loaded event
:
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
if (size != null)
{
var newwidth = Convert.ToInt32(size[0]) - 300;
var newheight = Convert.ToInt32(size[1]) - 200;
ApplicationView.GetForCurrentView().TryResizeView(new Size { Width = newwidth, Height = newwidth });
}
}
private string[] size;
protected override void OnNavigatedTo(NavigationEventArgs e)
{
if (e.Parameter.ToString() != "")
{
size = e.Parameter.ToString().Split(':');
}
}
或者,如果您不介意查看新窗口的大小调整过程,您也可以尝试使用此代码,并且无需在此方法中将size作为参数发送到新窗口:
var frame = new Frame();
frame.Navigate(typeof(MainPage), null);
newWindow.Content = frame;
newWindow.Activate();
await ApplicationViewSwitcher.TryShowAsStandaloneAsync(
newAppView.Id,
ViewSizePreference.UseHalf,
currentAV.Id,
ViewSizePreference.UseHalf);
newAppView.TryResizeView(new Size { Width = rect.Width - 300, Height = rect.Height - 200 });