Avançar para o conteúdo principal

Single Page App with C# WPF/XAML

 In this post we are going to create a single page app. The app will have multiple pages that get rendered in the main window. We will be using Visual Studio, C#, WPF and XAML.

Let's start by creating a new project in Visual Studio of this type:


Next, in the MainWindow, we define the interface structure.


On the left side we place a menu and on the right side a DockPanel with a Frame in it.


The Frame is the element that is used to render de pages content.

Now let's add the new pages. In this example I will add two pages. Click in the Solution Explorer with the mouse right button, then choose Add and Page.


The project looks like this.


The app content goes on the recently create pages. Because this is just an example I will just change the background color and add a small text.

Page1


Page2


Finally the code. Back to the MainWindow we need to create the click events on the menu items. So, in the MenuItem line add the click event and pick New Event Handler.

If that option doesn't show up just press CTRL+SPACE.

Visual Studio will generate the functions associated with the events, press F7 to go edit them.

Each function just needs one line of code, like so:


With this code the Page1 content will be rendered in the Frame of the MainWindow. Change the other function for Page2.

And that's it.

The project is here.


Comentários

Mensagens populares deste blogue

Let's make a car in Unity 3D

In this post we will make a simple car in Unity 3D. The Unity 3D physics engine is used in order to give the car a real behavior. This are the steps: [1] - Create a new Project

PacMan 3D

In this post we will be making a simple and classic game, the Pacman, with Unity 3D. Let's create a new a new project

Upgrading Windows 10 Home to Pro

 So I have been thinking about upgrading my Windows 10 Home Edition to the Pro version, but I always get to the point where it seems that I had to reinstall the entire SO and quit. After some investigating I have done it this way: - following this post  on the microsoft site I use one of the default keys for Windows 10 Pro and went to Settings > Update & Security > Activation > Change the product key; - next, Windows will activate the Pro functionalities and asks to restart; - now you have the Pro version but it's not activated, so you have to buy a Windows Pro Key. I went to UR cdkeys  and bought a key for less then €20; - and with the new key went to Change the product key and activated; - and it's done. Disclaimer : I have nothing to do with UR cdkeys so you can use any site to buy you cd key and your experience may vary from mine.