Adding the UWP View
Create a new folder called Views into the root folder of the MvvmCrossDemo.Uwp project. Add a Blank Page file called FirstView.xaml into the Views folder.
Open the FirstView.xaml.cs file and Change the base class of the FirstView class to MvxWindowsPage, like this:
1
using MvvmCross.Platforms.Uap.Views;
2
using MvvmCross.ViewModels;
3
using MvvmCrossDemo.Core.ViewModels;
4
5
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
6
7
namespace MvvmCrossDemo.Uwp.Views
8
{
9
/// <summary>
10
/// An empty page that can be used on its own or navigated to within a Frame.
11
/// </summary>
12
[MvxViewFor(typeof(FirstViewModel))]
13
public sealed partial class FirstView : MvxWindowsPage
14
{
15
public FirstView()
16
{
17
this.InitializeComponent();
18
}
19
}
20
}
Copied!
You might notice that we added a MvcViewForAttribute to the FirstView class. So MvvmCross can attach the right ViewModel to it.
Open the FirstView.xaml file, and replace the content with these codes:
1
<views:MvxWindowsPage
2
x:Class="MvvmCrossDemo.Uwp.Views.FirstView"
3
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5
xmlns:local="using:MvvmCrossDemo.Uwp.Views"
6
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8
xmlns:views="using:MvvmCross.Platforms.Uap.Views"
9
mc:Ignorable="d"
10
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
11
12
<StackPanel>
13
<TextBlock Text="Your Name"></TextBlock>
14
<TextBox Text="{Binding UserName, Mode=TwoWay}"></TextBox>
15
<Button Content="Click Me!" Command="{Binding GetGreetingCommand}"></Button>
16
<TextBlock Text="{Binding Greeting}"></TextBlock>
17
</StackPanel>
18
</views:MvxWindowsPage>
Copied!
Make sure to change the Page to views:MvxWindowsPage and add the namespace reference by this code:
1
xmlns:views="using:MvvmCross.Platforms.Uap.Views"
Copied!
Last modified 3yr ago
Copy link