WPF CommandParameter的使用
<Window x:Class="Wpf180706.Window5"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window5" Height="300" Width="300">
<Window.CommandBindings>
<CommandBinding Command="New" Executed="New_Execute" CanExecute="New_CanExecute"></CommandBinding>
</Window.CommandBindings>
<Grid>
<StackPanel>
<TextBox Name="txt"></TextBox>
<Button Name="newTeacher" Command="New" CommandParameter="Teacher">NewTeacher</Button>
<Button Name="newStudent" Command="New" CommandParameter="Student">NewStudent</Button>
<TextBlock Name="msg"></TextBlock>
</StackPanel>
</Grid>
</Window>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace Wpf180706
{
/// <summary>
/// Interaction logic for Window5.xaml
/// </summary>
public partial class Window5 : Window
{
public Window5()
{
InitializeComponent();
}
private void New_Execute(object sender, ExecutedRoutedEventArgs e)
{
msg.Text = e.Parameter.ToString();
}
private void New_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
if (string.IsNullOrEmpty(txt.Text))
{
e.CanExecute = false;
}
else
{
e.CanExecute = true;
}
}
}
}
WPF CommandParameter的使用的更多相关文章
- 【WPF】CommandParameter解决多传参问题
方法一:传参按钮控件自身绑定的ItemSource 用WAF框架实现MVVM,按钮的点击事件都要通过Command来传递到这个View对应的ViewModel上,再通过ViewModel传递到上层的C ...
- wpf mvvm模式下CommandParameter传递多参
原文:wpf mvvm模式下CommandParameter传递多参 CommandParameter一般只允许设置一次,所以如果要传递多参数,就要稍微处理一下.我暂时还没找到更好的方案,下面介绍的这 ...
- WPF ContextMenu 在MVVM模式中绑定 Command及使用CommandParameter传参
原文:WPF ContextMenu 在MVVM模式中绑定 Command及使用CommandParameter传参 ContextMenu无论定义在.cs或.xaml文件中,都不继承父级的DataC ...
- WPF命令参数CommandParameter
XAML代码如下: <Window x:Class="Demo006.MainWindow" xmlns="http://schemas.microsoft.com ...
- WPF命令參数CommandParameter
XAML代码例如以下: <Window x:Class="Demo006.MainWindow" xmlns="http://schemas.microsoft.c ...
- WPF中ContextMenu通过CommandParameter传参
场景:ListBox中有个ContextMenu,希望点击其中一个菜单项的时候把ListBox当做CommandParameter传递给Command,但是发现无论是通过ElementName还是Re ...
- [WPF]解决模板中ContextMenu绑定CommandParameter的问题
直接上代码,首先是一个ContextMenu的模板: <ContextMenu x:Key="Menu" BorderThickness="0.3" Fo ...
- WPF中DataGrid控件内Button的Command和CommandParameter的绑定
场景:视频上传功能,上传列表使用DataGrid控件,视频有不同的状态对应不同的操作,DataGrid中最后一列为操作列,里面是Button控件.希望点击Button后执行对应的操作,但是设置Butt ...
- WPF 通过 CommandParameter 传递当前窗体到 ViewModel
在应用 Command 模式中,需要在View上点击 一个按钮,需要将当前窗体作为参数传递为 command 两种方式传递当前窗体1.通过窗体名称(假设窗体名称为 ThisWindow) < ...
随机推荐
- linux 系统升级中的一些配置
1. 关闭IPV6 vi /etc/sysconfig/network NETWORKING_IPV6=no #掉 source /etc/sysconfig/network vi /etc/m ...
- 【u003】计算概率
Time Limit: 1 second Memory Limit: 128 MB [问题描述] 小明有n个长度不一的小木棍,这些木棍的长度都是正整数.小明的父亲想和小明做一个游戏.他规定一个整数长度 ...
- 忙里偷闲( ˇˍˇ )闲里偷学【C语言篇】——(3)输入输出函数
一.基本的输入和输出函数的用法 1.printf() //屏幕输出 用法: (1)printf("字符串\n"); (2)printf("输出控制符", 输出 ...
- [Postgres] Filter Data in a Postgres Table with Query Statements
We have all this data, but how do we answer questions about it? In this lesson we’ll learn how to fi ...
- Java多线程编程— 概念以及经常使用控制
多线程能满足程序猿编写很有效率的程序来达到充分利用CPU的目的,由于CPU的空暇时间可以保持在最低限度.有效利用多线程的关键是理解程序是并发运行而不是串行运行的.比如:程序中有两个子系统须要并发运行, ...
- require.js的用法详解
require.js的诞生是为了解决两大问题,第一实现js文件的异步加载,避免网页失去响应,第二管理模块之间的依赖性,便于代码的编写和维护. 一.为什么要用require.js? 最早的时候,所有Ja ...
- 小强的HTML5移动开发之路(26)—— JavaScript回顾1
很久没有怎么用过JavaScript了,感觉有点生疏,最近在看关于HTML5移动开发方面的资料,有一种直觉告诉我,JavaScript昨天.今天很重要,明天会更重要.现在好多基于JavaScript的 ...
- js中多层复杂并且动态键值JSON的获取方法
开发中遇到了用js解析重新组装json数据的要求,关键点在于JSON中的串的键是动态的,多方查找解决了在此做个记录.同时我也深感js中循环的无赖,如果用i作为键会得到索引,用key作为循环变量竟然可以 ...
- CentOS7查看开放端口命令
CentOS7查看开放端口命令 CentOS7的开放关闭查看端口都是用防火墙来控制的,具体命令如下: 查看已经开放的端口: /tcp --permanent 命令含义: –zone #作用域 –a ...
- unityd 公布android apk相关
http://game.ceeger.com/forum/read.php?tid=5918&ds=1 相关的文章非常多,我仅仅记录自己遇到的一些关键点. 1.jdk android SDK ...