你的位置:首页 > 软件开发 > ASP.net > WPF MvvmLight简单实例 页面导航

WPF MvvmLight简单实例 页面导航

发布时间:2016-04-05 22:00:15
实现了那些功能,先看看截图: 操作描述:在程序运行后,点击“Load”按钮,页面会加载PageOne,点击PageOne页面中的“Next”按钮即可进入PageTwo页面,点击PageTwo页面中 ...

实现了那些功能,先看看截图:

WPF  MvvmLight简单实例 页面导航

 

WPF  MvvmLight简单实例 页面导航

操作描述:

在程序运行后,点击“Load”按钮,页面会加载PageOne,点击PageOne页面中的“Next”按钮即可进入PageTwo页面,

点击PageTwo页面中的“Next”即可进入PageThree页面,点击Back可返回Page1页面

第一步:新建工程并使用NuGet安装MvvmLight

第二步:添加Views文件夹并添加相应的ViewModel

本文主要描述如何使用MvvmLight实现简单的导航效果,所以页面基本上都是大同小异比较简单ViewModel也比较简单,所以这里只PageOne.xaml以及PageOneViewModel.cs

PageOne.xaml代码:

<Page x:Class="MvvmLightSample.Views.PageOne"   ="http://schemas.microsoft.com/get='_blank'>winfx/2006/xaml/presentation"   ="http://schemas.microsoft.com/winfx/2006/xaml"   ="http://schemas.open"    ="http://schemas.microsoft.com/expression/blend/2008"    ="clr-namespace:MvvmLightSample.Views"   mc:Ignorable="d"      Title="PageOne">  <Page.DataContext>    <Binding Path="PageOne" Source="{StaticResource Locator}"></Binding>  </Page.DataContext>  <Grid Background="Orange">    <TextBlock Text="1" Foreground="White" FontSize="30"></TextBlock>    <StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">      <TextBlock Text="{Binding Title}" FontSize="18" Foreground="White"></TextBlock>      <Button Width="80" Height="20" Content="Click me!!!" Margin="0,20,0,0" Command="{Binding ChangeCommand}"></Button>    </StackPanel>    <Button Command="{Binding GoToNextCommand}" Content="Next" Width="60" Height="30" VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="0,0,10,10"></Button>  </Grid></Page>

原标题:WPF MvvmLight简单实例 页面导航

关键词:wpf

wpf
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。