-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[UWP] Fixes for font when using MultiWindow #11752
Conversation
Regarding the fix for resizing secondary windows, my suggestion was a workaround. Can you please investigate why that is not an issue for the main window? I would think that they should be resized in the same way. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Split up this fix and the resizing one.
@@ -26,6 +26,10 @@ public async Task OpenSecondaryWindow(Type pageType) | |||
ContentPage instance = (ContentPage)Activator.CreateInstance(pageType); | |||
frame.Navigate(instance); | |||
Window.Current.Content = frame; | |||
Window.Current.SizeChanged += (sender, args) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@KPixel makes a good point - why does this work? We should pull this out and create a separate issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok i removed that code.. Also another code that works is something like this bellow. But we don't want to create a new Window right?
public class NewSecondaryWindowsPage : WindowsPage
{
protected override void OnNavigatedTo(Windows.UI.Xaml.Navigation.NavigationEventArgs e)
{
var pageType = e.Parameter as Type;
ContentPage instance = (ContentPage)Activator.CreateInstance(pageType);
RegisterWindow(instance);
base.OnNavigatedTo(e);
}
}
public async Task OpenSecondaryWindow(Type pageType)
{
CoreApplicationView newView = CoreApplication.CreateNewView();
int newViewId = 0;
await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
var frame = new Windows.UI.Xaml.Controls.Frame();
Window.Current.Content = frame;
frame.Navigate(typeof(NewSecondaryWindowsPage), pageType);
Window.Current.Activate();
newViewId = ApplicationView.GetForCurrentView().Id;
});
bool viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newViewId);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. I think this points to the root of the issue: Application.MainPage...
I would like to create a new issue to discuss a solution there. Ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah the issue from what i understand is here :
var root = new Windows.UI.Xaml.Controls.Page(); |
We create a page just to fake it as "root" and so the code that listens to size changes here:
_container.SizeChanged += OnRendererSizeChanged; |
Doesn't work, because the _page (that we passed to the Platform) is not added to the VisualTree
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is also the following code which expects all windows to have a specific structure:
Xamarin.Forms/Xamarin.Forms.Platform.UAP/Platform.cs
Lines 51 to 59 in 3ca1250
internal static Platform Current | |
{ | |
get | |
{ | |
var frame = Window.Current?.Content as Windows.UI.Xaml.Controls.Frame; | |
var wbp = frame?.Content as WindowsBasePage; | |
return wbp?.Platform; | |
} | |
} |
So, your code above seems like the expected way to initialize a secondary window.
I've updated my app to follow this approach, and it works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means that the "fix" for the resize issue is to update OpenSecondaryWindow()
in the Control Gallery app.
Also, the PageExtensions class was a trap. From what I can see, in this entire repo, it is used in two scenarios:
- For
FormsEmbeddedPageWrapper
pages (and there is no sample/test for that). - For the UWP version of DualScreen. And I think that code should be updated to follow the
WindowsPage
approach, otherwise, it will suffer from the same resize bug.
Let's ship this fix! :) |
Hello, Can we please merge this simple fix before 5.0? It is ready to go! |
Description of Change
When using multiple windows we need to take in account that each CoreApplicationView has it's own thread so caching items doesn't work if they are shared. Like FontFamilies for example
We also need to relayout our contents when the window is resized.
Issues Resolved
API Changes
None
Platforms Affected
Behavioral/Visual Changes
None
Before/After Screenshots
Not applicable
Testing Procedure
Try open 2 our 3 windows from the control gallery
PR Checklist