刚学MVVM 百度了很多概念性的东西 也参考了网上的例子 基本有了了解

但是我发现 我做了一个登录页面以后 我跳转咋办呢? VM里面咋做跳转? 问了一下其他的群友得到了一些启发。感谢“上海*松”

我仅在此作为标记,贴出发给我的demo。

一下是登录页面:VLoginWindow.xaml  很简单 上面就一个按钮:

<Window x:Class="ShenJingBingDemo.View.VLoginWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
        xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
        xmlns:vm="clr-namespace:ShenJingBingDemo.ViewModel"
        Title="登录" Height="300" Width="300">
    <Window.DataContext>
        <vm:VMLoginWindow />
    </Window.DataContext>

    <i:Interaction.Triggers>
        <i:EventTrigger  EventName="Loaded">
            <ei:CallMethodAction TargetObject="{Binding}" MethodName="MainWindow_Loaded"/>
        </i:EventTrigger>
    </i:Interaction.Triggers>
    <Grid>
        <Button Content="登录" VerticalAlignment="Center" HorizontalAlignment="Center" Width="100" Height="60">
            <i:Interaction.Triggers>
                <i:EventTrigger  EventName="Click">
                    <ei:CallMethodAction TargetObject="{Binding}" MethodName="Btn_Login_Click"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </Button>
    </Grid>
</Window>

接下来是VM: VMLoginWindow.cs  跳转到MainWindow.xaml 主面板

using System.Windows;

namespace ShenJingBingDemo.ViewModel
{
    public class VMLoginWindow : NotificationObject
    {
        #region 变量
        Window win;
        #endregion 变量

        #region 事件
        public void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            win = sender as Window;

           // e.Handled = true;
        }

        public void Btn_Login_Click(object sender, RoutedEventArgs e)
        {
            MainWindow mainwin = new MainWindow();
            win.Close();
            mainwin.ShowDialog();

          //  e.Handled = true;
        }

        #endregion 事件

    }
}

还有demo里实现响应的NotificationObject.cs

using System;
using System.ComponentModel;
using System.Linq.Expressions;
using System.Reflection;
namespace ShenJingBingDemo
{
    public abstract class NotificationObject : INotifyPropertyChanged
    {

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void RaisePropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = this.PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        protected void RaisePropertyChanged(params string[] propertyNames)
        {
            if (propertyNames == null) throw new ArgumentNullException("propertyNames");

            foreach (var name in propertyNames)
            {
                this.RaisePropertyChanged(name);
            }
        }

        protected void RaisePropertyChanged<T>(Expression<Func<T>> propertyExpression)
        {
            var propertyName = ExtractPropertyName(propertyExpression);
            this.RaisePropertyChanged(propertyName);
        }

        public static string ExtractPropertyName<T>(Expression<Func<T>> propertyExpression)
        {
            if (propertyExpression == null)
            {
                throw new ArgumentNullException("propertyExpression");
            }

            var memberExpression = propertyExpression.Body as MemberExpression;
            if (memberExpression == null)
            {
                throw new ArgumentException("PropertySupport_NotMemberAccessExpression_Exception", "propertyExpression");
            }

            var property = memberExpression.Member as PropertyInfo;
            if (property == null)
            {
                throw new ArgumentException("PropertySupport_ExpressionNotProperty_Exception", "propertyExpression");
            }

            var getMethod = property.GetGetMethod(true);
            if (getMethod.IsStatic)
            {
                throw new ArgumentException("PropertySupport_StaticExpression_Exception", "propertyExpression");
            }

            return memberExpression.Member.Name;
        }

    }
}

代码是这么个代码,上面加的俩命名空间其实是引用

C:\Program Files (x86)\Microsoft SDKs\Expression\Blend\.NETFramework\v4.0\Libraries

下面的俩类库Microsoft.Expression.Interactions 和System.Windows.Interactivity。看样子是blend的里面的,用的时候记得添加引用。

标记一下,匆匆下班,再见各位。

MVVM页面跳转 技巧性标记的更多相关文章

  1. JSP页面跳转的几种实现方法

    使用href超链接标记      客户端跳转 使用JavaScript               客户端跳转 提交表单                        客户端跳转 使用response ...

  2. Response.Write页面跳转

    一.<a>标签 <a href=”test.aspx”></a> 这是最常见的一种转向方法 二.HyperLink控件   1. Asp.net 服务器端控件 属性 ...

  3. ios&h5混合开发项目仿app页面跳转优化

    前言:本人原本是ios开发工程师,但由于现今H5的兴起,行内刮起了一阵混合开发的风气,趁着这股劲,我也学了前端开发,不说研究的多深,但也能胜任日常的开发工作.长话短说,现今的混合开发应该还处于摸索阶段 ...

  4. ASP.NET页面跳转的三种方法比较

    在ASP.NET下,经常需要在页面之间跳转,下面我们来分别介绍一下关于.NET中Response.Redirect(),Sever.Execute(),Server.Transfer() 三种页面跳转 ...

  5. ASP.NET页面跳转

    总结一下跳转方式: <a>标签 <a href=”home.aspx”></a> HyperLink控件 Asp.net 服务器端控件 属性NavigateUrl指 ...

  6. [ExtJS5学习笔记]第二十五节 利用window.open()函数实现ExtJS5的登陆页面跳转

    本文地址:http://blog.csdn.net/sushengmiyan/article/details/40427543 mvvm方式实现登陆的博客:http://blog.csdn.net/s ...

  7. springMVC源码分析--页面跳转RedirectView(三)

    之前两篇博客springMVC源码分析--视图View(一)和springMVC源码分析--视图AbstractView和InternalResourceView(二)中我们已经简单的介绍了View相 ...

  8. 问题:asp.net 点击button按钮调到页面顶部;结果:asp.net点击一个按钮,使页面跳转到本面页上的指定位置

    asp.net点击一个按钮,使页面跳转到本面页上的指定位置 (2011-04-19 16:46:51) 转载▼ 标签: it   最近在做一个项目. 用到标题所说的功能. 实现方法: 1.在aspx中 ...

  9. web设计页面跳转的方法

    一.asp.net c# 打开新页面或页面跳转 1. 最常用的页面跳转(原窗口被替代):Response.Redirect("newpage.aspx"); 2. 利用url地址打 ...

随机推荐

  1. Node.js之路【第三篇】NodeJS异步实现

    NodeJS异步实现 Node.js异步编程的直接体现就是回调,它依托于回调来实现,但不能说使用了回调他就是异步了 回调函数在完成任务后就会被调用,Node使用了大量的回调函数,Node所有的API都 ...

  2. 关于HTML5本地缓存技术LocalStorage 本地存储 和 SessionStorage

    如果你想在用户访问的时候记录或者记住他们的行为,你会想到的是什么,cookie 和session.但今天告诉你还有两种或者说是1种吧 那就是html5的 LocalStorage 本地存储和 Sess ...

  3. SVN搭建简单教程

    一.引言 笔者曾经试图在网上搜索一篇关于SVN源代码服务器搭建方面的中文技术文章,可惜,所找到的,要么是不完整,要么就是对笔者没什么帮助的文章,TortoiseSvn的帮助文档固然强大,但因为是英文, ...

  4. Azure的负载均衡机制

    负载均衡一直是一个比较重要的议题,几乎所有的Azure案例或者场景都不可避免,鉴于经常有客户会问,所以笔者觉得有必要总结一下. Azure提供的负载均衡机制,按照功能,可以分为三种:Azure Loa ...

  5. 动态令牌-(OTP,HOTP,TOTP)-基本原理

    名词解释和基本介绍 OTP 是 One-Time Password的简写,表示一次性密码. HOTP 是HMAC-based One-Time Password的简写,表示基于HMAC算法加密的一次性 ...

  6. shell脚本: 备份mysql远程数据库并清除一个月之前的数据

    hxingxing-backup.sh: date="$(date +"%Y-%m-%d")"mysqldump -u root -h localhost -p ...

  7. Burp Suite使用详解一

    本文由阿德马翻译自国外网站,请尊重劳动成果,转载注明出处 Burp Suite是Web应用程序测试的最佳工具之一,其多种功能可以帮我们执行各种任务.请求的拦截和修改,扫描web应用程序漏洞,以暴力破解 ...

  8. [转载]js中return的用法

    一.返回控制与函数结果,语法为:return 表达式; 语句结束函数执行,返回调用函数,而且把表达式的值作为函数的结果 二.返回控制,无函数结果,语法为:return;  在大多数情况下,为事件处理函 ...

  9. 提交本地项目到github

    要托管到github,那你就应该要有一个属于你自己的github帐号,所以你应该先到github.com注册 打开浏览器 在地址栏输入地址:github.com 填写用户名.邮箱.密码 点击Sign ...

  10. C#操作access和SQL server数据库代码实例

    在C#的学习中,操作数据库是比较常用的技术,而access和sql server 数据库的操作却有着不同.那么,有哪些不同呢? 首先,需要引用不同的类.因为有着不同的数据引擎. access:usin ...