Adding the View for the UWP project
Add a button to the FirstView.xaml in the Views folder of the MvvmCrossDemo.Uwp project and bind the NavToPostListAsyncCommand command of the FirstViewModel.cs, as shown below:
1
<TextBlock Text="{Binding Greeting}"></TextBlock>
2
<Button Content="Post List" Command="{Binding NavToPostListAsyncCommand}"></Button>
Copied!
Create a new Blank Page item called PostListView.xaml to the Views folder in the MvvmCrossDemo.Uwp project. Open PostListView.xaml.cs and change the base class to MvxWindowsPage class, like this:
1
namespace MvvmCrossDemo.Uwp.Views
2
{
3
[MvxViewFor(typeof(PostListViewModel))]
4
public sealed partial class PostListView : MvxWindowsPage
5
{
6
public PostListView()
7
{
8
this.InitializeComponent();
9
}
10
}
11
}
Copied!
Open PostListView.xaml and replace the content with the following codes:
1
<views:MvxWindowsPage
2
x:Class="MvvmCrossDemo.Uwp.Views.PostListView"
3
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
7
mc:Ignorable="d"
8
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
9
xmlns:views="using:MvvmCross.Platforms.Uap.Views" >
10
<Grid>
11
</Grid>
12
</local:BaseView>
Copied!
Add a ListView control to the root layout and define the item template, like this:
1
<Grid>
2
<ListView ItemsSource="{Binding PostList}">
3
<ListView.ItemTemplate>
4
<DataTemplate>
5
<StackPanel HorizontalAlignment="Stretch">
6
<TextBlock Text="{Binding Title}" Style="{StaticResource TitleTextBlockStyle}"></TextBlock>
7
<TextBlock Text="{Binding Body}"></TextBlock>
8
</StackPanel>
9
</DataTemplate>
10
</ListView.ItemTemplate>
11
</ListView>
12
</Grid>
Copied!
Open the Package.appxmanifest file and select Capabilities tab, and make sure the Internet (Client) option is checked. Here is the result:
Last modified 3yr ago
Copy link