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) < ...
随机推荐
- hibernate级联保存问题
异常:org.hibernate.TransientObjectException: object references an unsaved transient instance 解决方法: XML ...
- https://sourceware.org/gdb/onlinedocs/gdb/Forks.html
https://sourceware.org/gdb/onlinedocs/gdb/Forks.html Next: Checkpoint/Restart, Previous: Threads, Up ...
- .Net Core身份认证:IdentityServer4实现OAuth 2.0 客户端模式 - 简书
原文:.Net Core身份认证:IdentityServer4实现OAuth 2.0 客户端模式 - 简书 一.客户端模式介绍 客户端模式(Client Credentials Grant)是指客户 ...
- 【浅墨Unity3D Shader编程】之中的一个 夏威夷篇:游戏场景的创建 & 第一个Shader的书写
本系列文章由@浅墨_毛星云 出品.转载请注明出处. 文章链接:http://blog.csdn.net/poem_qianmo/article/details/40723789 作者:毛星云(浅墨) ...
- JS调用ATL COM中的C++接口的做法
作者:朱金灿 来源:http://blog.csdn.net/clever101 首先创建一个ATL COM对象,其过程参考下面文章: C#调用ATLCOM 其实给COM对象添加方法和属性可以不用界面 ...
- ios tableView那些事
iOS开发很重要的一个功能就是tableView,可以说熟练使用tableView是iOS开发必修的课程,网上很多相关介绍,推荐一个博客参考一下: http://blog.csdn.net/lengs ...
- app.config中的值获取及设置 以及对log4net配置
修改或新增AppSetting节点 /// <summary> /// 修改AppSettings中配置 /// </summary> /// <param name ...
- Java对象基础的一些小问题
1 权限修饰符public protected private default..访问权限修饰符 public protected default private 同类 T T T T 同包 T ...
- Docker + .NET Core(二)
原文:Docker + .NET Core(二) 前言: 环境:centos7.5 64 位 正文: 首先我们在宿主机上安装 .NET Core SDK sudo rpm --import https ...
- Visual Studio 2017 and Apache Cordova mobile apps | Andrés Zsögön
原文:Visual Studio 2017 and Apache Cordova mobile apps | Andrés Zsögön 以下是使用Microsoft Visual Studio 20 ...