-
Notifications
You must be signed in to change notification settings - Fork 693
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: WinUI 3 - File New Project Template should create a MainPage
and not just a MainWindow
#5515
Comments
Hello @michael-hawker, I agree. Do you have a sample application where I can copy from. Since I share code between UWP WinUI 2 & Win32 WinUI 3, it would help me a lot if I can share the MainPage as well. I saw that the WinUI 3 Controls Gallery uses this approach, but this code is quite complex. Thanks, |
@crramirez I unfortunately do not have anything setup. Most of my WinUI 3 tests have just been dropping in our Toolkit controls to check that they're working. At a minimum though you can basically replicate what the <!-- MainWindow.xaml -->
<Window ...>
<Frame x:Name="ApplicationFrame"/>
</Window> // MainWindow.xaml.cs
public MainWindow()
{
this.InitializeComponent();
ApplicationFrame.Navigate(typeof(MainPage));
} I think that should work, just copy over your MainPage class and tweak its namespaces and then you should see it as your starting page, just like in an UWP app. (Btw, love your github stat blog on your readme, is there a site to help generate that? Is it 'live' or static that you have to re-generate?) |
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:
|
@evelynwu-msft FYI |
Frame isn't needed by default. If the user wants back and forward navigation, they can add it manually. Today the UWP templates add a root frame but I don't like that and usually, I just make MainPage a user control and set it as the content. |
Yeah, I think in the default case developers may want to know how to handle page navigation. It's easier for a dev to rip the frame out than realize that it's missing. That's also why #5513 is important to point devs to the right docs for getting started or be able to find tools like Windows Template Studio to be able to make it easier to configure their app design/setup. |
MainPage
and not just a MainWindowMainPage
and not just a MainWindow
FYI similar to binding this also prevents a |
If anything, the template could just create a <Window x:Class="ProjectTemplate.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:ProjectTemplate"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<!-- Window isn't a FrameworkElement for dependency property or resources... -->
<local:MainPage />
</Window> 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 |
Originally posted by @michael-hawker in #4966 (comment)
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 implicitFrame
that UWP apps used to create back inApp.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 aMainPage
object based onPage
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 aDependencyProperty
off of it (see #4966 for instance).The text was updated successfully, but these errors were encountered: