刚学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. 12月4日PHPCMS模板

    cms的样式有很多种,我们学习的是phpcms,这些cms都是大同小异,学会了一种就可以使用其它的cms. PHPCMS是一款网站管理软件.该软件采用模块化开发,支持多种分类方式,使用它可方便实现个性 ...

  2. RESTful API URI 设计的一些总结

    非常赞的四篇文章: Resource Naming Best Practices for Designing a Pragmatic RESTful API 撰写合格的 REST API JSON 风 ...

  3. Git on Windows 一些问题

    问题汇总 1. 卸载Git时,bin和usr目录删不掉 报错:bin, usr目前需要admin权限删除,或者这个目录被其他文件引用 打开taskmgr,找到所有引用 git/bin/ 下的文件的进程 ...

  4. Datalogic组网模式下通讯

    1.首先要在visiset工具下,设置好地址端口号,组网模式master slave参数: 2.打开工具hercules,选择TCP Client选项,设置参数好连接并通讯,发送打开.关闭 按钮指令, ...

  5. CSS3教程:box-sizing属性的理解

    说到 IE 的 bug,一个臭名昭著的例子是它对于“盒模型”的错误解释:在 IE5.x 以及 Quirks 模式的 IE6/7 中,将 border 与 padding 都包含在 width 之内.这 ...

  6. struts1和struts2的区别

    1. 在Action实现类方面的对比:Struts 1要求Action类继承一个抽象基类:Struts 1的一个具体问题是使用抽象类编程而不是接口.Struts 2 Action类可以实现一个Acti ...

  7. DataTable to Excel(使用NPOI、EPPlus将数据表中的数据读取到excel格式内存中)

    /// <summary> /// DataTable to Excel(将数据表中的数据读取到excel格式内存中) /// </summary> /// <param ...

  8. 推荐一些国内的Jquery CDN免费服务

    Jquery是个非常流行的JS前端框架,在很多网站都能看到它的身影.很多网站都喜欢采用一些Jquery CDN加速服务,这样网站加载jquery会更快.之前火端网络的一些网站都是使用Google的jq ...

  9. 在XP上运行IIS5.1新建站点

    系统问题,XP下IIS5.1不能直接新建站点,因为内核限制只能同时运行一个站点,要想新建站点,必须把当前站点停掉,然后用adsutil.vbs脚本创建,脚本在C:\Inetpub\AdminScrip ...

  10. org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [XXX] in DispatcherServlet with name 'springMVC'

    在web.xml中添加 <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern ...