UWP NavigationMenu with only C# source code

120 Views Asked by At

Introduction

When I look at tutorials on how to develop a navigation menu in UWP design, all I see is XAML code being used.

Problem

I can't find any other video tutorials on how to develop a navigation menu in C# code only.

Question

How can I develop this navigation (See Image) menu using only C#?

Screenshot of the Navigationmenu

1

There are 1 best solutions below

0
dear_vv On

The use of Xaml files is to separate the UI and the code. Once the UI code is mixed with logic code, the app will become very bloated and difficult to maintain.

So it is more convenient to use the XAML code design. If you do want to do this by code-behind, please refer to the following code.

NavigationView navigationView = new NavigationView();           
var Item1 = new NavigationViewItem() { Content = "Item1", Icon = new SymbolIcon(Symbol.Download) };
var Item1 = new NavigationViewItem() { Content = "Item2", Icon = new SymbolIcon(Symbol.Page) }; 
navigationView .MenuItems.Add(Item1);
navigationView .MenuItems.Add(Item2);                       
MyGrid.Children.Add(navigationView );