0

I am trying to navigate via code-behind in my WinUI3 desktop application. I have found this article that explains how to do it. https://xamlbrewer.wordpress.com/2021/07/06/navigating-in-a-winui-3-desktop-application/

The author of the article has this section:

*Then we exposed the implementation via the App instance – it knows the Shell because it creates it on start-up:

private Shell shell;
 
public INavigation Navigation => shell;
         
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
    shell = new Shell();
    shell.Activate();
}*

I mainly understand all of the setup that will be required to navigate via code-behind, but I did not understand that one line of code "public INavigation Navigation => shell;"

My code, where I will insert similar code once I build the interface, etc., looks like this:

namespace MetricReporting
{
    public partial class App : Application
    {
        public App()
        {
            this.InitializeComponent();
        }

        protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
        {
            m_window = new MainWindow();
            m_window.Activate();
        }

        private Window m_window;
    }
}

That code line in question should be "public INavigation Navigation => m_window;" (This is my understanding) to work with my application.

I appreciate anyone who can explain what this line is doing. Sincerely.

LennyL
  • 225
  • 3
  • 9
  • That's just a readonly expression-bodied property. It's the equivalent of `public INavigation Navigation { get { return shell; } }` – Jon Skeet Feb 25 '22 at 07:09
  • Hi Jon, thank you very much for your reply. Have you seen this technique used before? – LennyL Mar 02 '22 at 07:12
  • What, readonly expression-bodied properties? Yes, they're very common in modern code. – Jon Skeet Mar 02 '22 at 07:25

0 Answers0