MVVM页面跳转 技巧性标记
刚学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页面跳转 技巧性标记的更多相关文章
- JSP页面跳转的几种实现方法
使用href超链接标记 客户端跳转 使用JavaScript 客户端跳转 提交表单 客户端跳转 使用response ...
- Response.Write页面跳转
一.<a>标签 <a href=”test.aspx”></a> 这是最常见的一种转向方法 二.HyperLink控件 1. Asp.net 服务器端控件 属性 ...
- ios&h5混合开发项目仿app页面跳转优化
前言:本人原本是ios开发工程师,但由于现今H5的兴起,行内刮起了一阵混合开发的风气,趁着这股劲,我也学了前端开发,不说研究的多深,但也能胜任日常的开发工作.长话短说,现今的混合开发应该还处于摸索阶段 ...
- ASP.NET页面跳转的三种方法比较
在ASP.NET下,经常需要在页面之间跳转,下面我们来分别介绍一下关于.NET中Response.Redirect(),Sever.Execute(),Server.Transfer() 三种页面跳转 ...
- ASP.NET页面跳转
总结一下跳转方式: <a>标签 <a href=”home.aspx”></a> HyperLink控件 Asp.net 服务器端控件 属性NavigateUrl指 ...
- [ExtJS5学习笔记]第二十五节 利用window.open()函数实现ExtJS5的登陆页面跳转
本文地址:http://blog.csdn.net/sushengmiyan/article/details/40427543 mvvm方式实现登陆的博客:http://blog.csdn.net/s ...
- springMVC源码分析--页面跳转RedirectView(三)
之前两篇博客springMVC源码分析--视图View(一)和springMVC源码分析--视图AbstractView和InternalResourceView(二)中我们已经简单的介绍了View相 ...
- 问题:asp.net 点击button按钮调到页面顶部;结果:asp.net点击一个按钮,使页面跳转到本面页上的指定位置
asp.net点击一个按钮,使页面跳转到本面页上的指定位置 (2011-04-19 16:46:51) 转载▼ 标签: it 最近在做一个项目. 用到标题所说的功能. 实现方法: 1.在aspx中 ...
- web设计页面跳转的方法
一.asp.net c# 打开新页面或页面跳转 1. 最常用的页面跳转(原窗口被替代):Response.Redirect("newpage.aspx"); 2. 利用url地址打 ...
随机推荐
- latex均方极限符号l.i.m在lyx下的输入方法
$\mathop{l.i.m}\limits_{x\to +\infty}$ 命令说明: 1.指定数学环境$$ 2.\mathop{l.i.m}指数学符号自定义为l.i.m 3.\limits_{x\ ...
- 的vim和emacs常用配置记录
因为经常改变工作环境,所以在这里记录一下我的.vimrc文件和.emacs文件的内容. vimrc的配置文件,主要是设置语法高亮,和tab键的宽度,个人喜欢设置为4个空格的分量. " set ...
- JavaMail: SSL vs TLS vs STARTTLS
SSL vs TLS vs STARTTLS There's often quite a bit of confusion around the different terms SSL, TLS an ...
- android中xml tools属性详解
第一部分 安卓开发中,在写布局代码的时候,ide可以看到布局的预览效果. 但是有些效果则必须在运行之后才能看见,比如这种情况:TextView在xml中没有设置任何字符,而是在activity中设置了 ...
- 报错注入分析之Extractvalue分析
Extractvalue(这单词略长,拆分记忆法extract:提取物 value:值) 上一篇说的是updatexml.updatexml是修改的.而evtractvalue是查询的. 用法与upd ...
- VS2013全攻略
http://blog.csdn.net/cpp12341234/article/details/45371269 挺好的,喜欢
- Python读写csv
读取csv: http://blog.csdn.net/lixiang0522/article/details/7755059 读取Excel: http://www.cnblogs.com/lhj5 ...
- 函数find(exp)
Matlab函数find(exp): 查找符合exp的值并储存 示例: b=find(a>20&a<40) 仅此
- 使用KRPano资源分析工具强力加密KRPano项目(XML防破解,切片图保护,JS反调试)
软件交流群:571171251(软件免费版本在群内提供) krpano技术交流群:551278936(软件免费版本在群内提供) 最新博客地址:blog.turenlong.com 限时下载地址:htt ...
- UIPickerView去掉背景上的黑线
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger) ...