Proposal: WinUI 3 - File New Project Template should create a `MainPage` and not just a MainWindow
See original GitHub issue_Originally posted by @michael-hawker in https://github.com/microsoft/microsoft-ui-xaml/issues/4966#issuecomment-882958799_
Yeah, I too keep getting tripped up that Window isn’t a
DependencyObject
… it’s a bit weird.If the expectation that
Window
is supposed to just be the host like the implicitFrame
created inApp.xaml.cs
for UWP apps, maybe the File -> New template for WinUI 3 should separate out theMainWindow
as also having aMainPage
class hosted by it already setup?This would help lead developers to the proper constructs when building their app and set them up for success vs. having everyone start dumping UI in
MainWindow
and then getting frustrated.I mean I really like how the
MainWindow
is more exposed compared to all the extra logic on Startup that was done in the UWP space, but it’s super confusing and bare-bones template when trying to start building an app from afterwards without creating a newPage
first.
I keep seeing a few issues filed because of this (and have been tripped up myself) by the fact that the default project template for WinUI 3 creates a bare Window
class.
This doesn’t jive as well with many UI APIs as it’s not a DependencyObject
/FrameworkElement
. It’s really just the application ‘shell’, like the implicit Frame
that UWP apps used to create back in App.xaml.cs
.
I love that this Window is now exposed and more easily customizable via XAML, but feel like it should still host a Frame
which then points to a MainPage
object based on Page
where a developer is then led to start creating their application’s UI.
Otherwise, developers just start building UI within the Window
itself and get tripped up when something needs to navigate the visual tree or try to create a DependencyProperty
off of it (see #4966 for instance).
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:9 (4 by maintainers)
Top GitHub Comments
If anything, the template could just create a
MainPage
and reference it in the Window XAML:This is what I did in my template (though I’m also sharing the MainPage with the UWP head in the case anyway): https://github.com/michael-hawker/WinUI2Plus3Template/blob/main/ProjectTemplate.WinAppSDK/MainWindow.xaml
Though in the onboarding/getting started docs there should still be information here about how to setup and use a
Frame
model (if needed) like what is setup by default in a UWP app or alternatively hosting aNavigationView
with aFrame
inside it. Though it definitely needs to be called out somewhere that Window isn’t mean to be used with XAML markup constructs, see folks running into this pitfall, mostly with binding, all the time.Ok, I will begin with that. I agree with you that this could help everyone to migrate a UWP app to WinUI 3 easier.
I copied the stats from another user 😏 . This is the code:
![Carlos Ramirez's GitHub Stats](https://github-readme-stats.vercel.app/api?username=crramirez&show_icons=true&count_private=true)