刚学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. ParamTest

    package fourth; public class ParamTest { public static void main(String[] args) { // TODO Auto-gener ...

  2. Spring MVC学习笔记——SiteMesh的使用(转)

    转自 SiteMesh的使用 SiteMesh的介绍就不多说了,主要是用来统一页面风格,减少重复编码的. 它定义了一个过滤器,然后把页面都加上统一的头部和底部. 需要先在WEB-INF/lib下引入s ...

  3. 红米2A高配刷机记录

    2014816 机型:红米2A高配版 设备型号:2014816 CPU:高通 线刷:fastboot平台 http://192.168.7.118/MesReports/Reports/Cutting ...

  4. IOS开发遇到(null)与<null>轻松处理

    在ios开发中不可避免的我们会遇到服务器返回的值有空值,但是如果是nil也就算了还可能得到(null)以及<null>的返回值,该如何处理呢?(当然有的字典转模型中已处理,可以通过遍历等) ...

  5. Spring学习记录1--@Transactional Propagation

    起因 学习Spring的时候就知道aop有一个应用是声明式注解..反正往Service上一丢@Transactional就完事了..不用自己去开启hibernate的session,很简单. 但是@T ...

  6. Android Textview实现文字颜色渐变效果

    最近做应用的时候遇到一个需求,一行文字的颜色需要一个渐变效果 如上所有 从左到有逐渐变化,自己写了一个demo实现上述效果 package com.huwei.example.test; import ...

  7. JavaScript - 正则表达之二

    正则表达式的大致匹配过程是:依次拿出表达式和文本中的字符比较,如果每一个字符都能匹配,则匹配成功:一旦有匹配不成功的字符则匹配失败. 正则表达式通常用于在文本中查找匹配的字符串.Python里数量词默 ...

  8. JavaScript数组去重

    第一种方法: 思路: 1.创建一个新的数组存放结果 2.创建一个空对象, 3.将数组中的元素作为空对象的属性并对其赋值,每次取出一个元素与对象进行对比,然后到对象中去访问这个属性, 如果能访问到值,则 ...

  9. poi2015 bzoj4377-4386训练

    就按时间顺序写吧 完成度:10/10 3.30 bzoj4385 首先一定是删去连续d个数,然后枚举终点,起点显然有单调性,用单调队列乱搞搞就可以啦 bzoj4378 首先才结论:可行当且仅当把所有大 ...

  10. Unity 编译错误记录

    1. 相关代码: NetworkView.RPC ("ReceiveMessage", RPCMode.All, message); 编译输出: Assets/cs/ClientC ...