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) < ...
随机推荐
- Centos6.5 VNC 配置
VNC 配置 本教程配置说明 目的:实现Window下VNC登陆Linux服务器 本机是在root用户下操作完毕 两台主机已实现基本网络配置,且相互ping通 1. 检查图形界面 确保服务器端须要执行 ...
- [Angular] NgRx/effect, why to use it?
See the current implementaion of code, we have a smart component, and inside the smart component we ...
- [Vue] Use Vue.js Watchers to Respond to Async Updates
Use watchers to keep an eye on your data. Watchers are methods that are invoked when the specified a ...
- 【u213&&t037】修剪花卉
Time Limit: 1 second Memory Limit: 128 MB [问题描述] ZZ对数学饱有兴趣,并且是个勤奋好学的学生,总是在课后留在教室向老师请教一些问题. 一天他早晨骑车去上 ...
- SpringMVC ModelAndView跳转失效
今天隔壁的兄弟遇到一个奇怪的问题,他写好了一个表单用post提交到了addNew.do 里面,然后利用 return new ModelAndView("forward:success.js ...
- Framework for Graphics Animation and Compositing Operations
FIELD OF THE DISCLOSURE The subject matter of the present disclosure relates to a framework for hand ...
- 回顾Oracle几个用到的基本语句
create table t_name(id number,name varchar2(10)); drop table t_name; select * from table_name where ...
- Android四大组件之Activity--管理方式
1. 概览 Activity的管理有静态和动态两层涵义: 静态是指Activity的代码组织结构,即Application中声明的Activity的集合,这些Activity被组织在一个APK中,有特 ...
- 新技能 get —— 五笔打字
推荐一个图表记忆网站,五笔字根表图五笔字根表五笔输入法下载口诀五笔打字练习_查询: 1. 键盘的认识 键盘的版式就是那样设定的,主要是 26 个拉丁字母,分三排: QWERT(撇区), YUIOP(捺 ...
- 防爆搜索解决方案hdu1572下沙面(2)
#include<iostream> #include<map> #include<string> #include<cstring> #include ...