理解Prism中MVVM的Command与CommandParameter
2012-04-14 10:44
363 查看
理解Prism中MVVM的Command与CommandParameter
内容摘要
接上一讲(/article/4661057.html),这一讲中我使用Prism做了演示和比较。Prism不仅仅是一个MVVM框架,它还包含其他的模块。在MVVM这个层面,Prism有些特殊性(Command绑定有特殊语法),这也是我这一讲的主要内容。Prism的下载链接
http://compositewpf.codeplex.com/视频地址
http://www.tudou.com/programs/view/72Ag1kQt1RA/示例代码
<Window x:Class="WPFPrismMvvm.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" xmlns:local="clr-namespace:WPFPrismMvvm" xmlns:cmd="clr-namespace:Microsoft.Practices.Prism.Commands;assembly=Microsoft.Practices.Prism" Width="525"> <Window.DataContext> <local:MainWindowViewModel UserName="chenxizhang"></local:MainWindowViewModel> </Window.DataContext> <Grid> <StackPanel> <TextBox Text="{Binding UserName,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"></TextBox> <Button Content="Show" cmd:Click.Command="{Binding ShowCommand}" cmd:Click.CommandParameter="{Binding UserName}"></Button> </StackPanel> </Grid> </Window>
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Practices.Prism.ViewModel; using Microsoft.Practices.Prism.Commands; using System.Windows.Input; using System.Windows; namespace WPFPrismMvvm { public class MainWindowViewModel:NotificationObject { private string _UserName; public string UserName { get { return _UserName; } set { if (_UserName != value) { _UserName = value; RaisePropertyChanged("UserName"); } } } public ICommand ShowCommand { get { return new DelegateCommand<string>( (user) => { MessageBox.Show(user); }, (user) => { return !string.IsNullOrEmpty(user); }); } } } }
相关文章推荐
- 理解Prism中MVVM的Command与CommandParameter
- 从PRISM开始学WPF(六)MVVM(二)Command?
- MVVM 的事件处理: 利用Prism框架进行EventToCommand
- Mvvm Light Toolkit for wpf/silverlight系列之Command和Events
- 稳扎稳打Silverlight(52) - 4.0绑定之 ICommand 命令和 MVVM 模式
- 稳扎稳打Silverlight(52) - 4.0绑定之 ICommand 命令和 MVVM 模式
- 稳扎稳打Silverlight(52) - 4.0绑定之 ICommand 命令和 MVVM 模式
- 从PRISM开始学WPF(五)MVVM(一)ViewModel?
- 从PRISM开始学WPF(七)MVVM(三)事件聚合器EventAggregator?
- Mvvm Light Toolkit for wpf/silverlight系列之Command和Events
- MVVM实践中的Command与CommandParameter的使用
- Mvvm Light Toolkit for wpf/silverlight系列之Command和Events
- mvvm的理解
- 为Windows Phone Mango MVVM 应用创建可复用 ICommand 实现类
- 从Prism中学习设计模式之MVVM 模式简述MVVM
- 再次理解MVC,MVP 和 MVVM 的图示
- 背水一战 Windows 10 (24) - MVVM: 通过 Binding 或 x:Bind 结合 Command 实现,通过非 ButtonBase 触发命令
- WPF新手实践5:MVVM Light Toolkit(五、Command)(转)
- 对Android中设计模式MVC,MVP,MVVM的简单理解
- 从CREATE 命令的层面再来理解一下DB2数据库(1)- CREATE DATABASE command