码迷,mamicode.com
首页 > Windows程序 > 详细

潜移默化学会WPF--Command(命令)学习(三) - AYUI框架 - 博客园

时间:2019-03-01 22:20:10      阅读:1463      评论:0      收藏:0      [点我收藏+]

标签:turn   send   man   idt   rip   xmlns   microsoft   win   none   

原文:潜移默化学会WPF--Command(命令)学习(三) - AYUI框架 - 博客园

3.修炼

   3.1 自定义命令

       涉及到的一些概念,例如 InputGestureCollection这个集合,路由命令(RoutedUICommand)等我们不用太紧张,潜移默化学会他们的用法,Ok,学习吧

     先看代码,先看后台

     

技术图片
using System.Collections.Generic;
using System.Text;
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 Commands
{

public partial class CustomCommand : System.Windows.Window
{
public CustomCommand()
{
InitializeComponent();
}

private void RequeryCommand(object sender, ExecutedRoutedEventArgs e)
{
MessageBox.Show("Requery");
}

}

public class DataCommands
{
private static RoutedUICommand requery;
static DataCommands()
{
InputGestureCollection inputs = new InputGestureCollection();
inputs.Add(new KeyGesture(Key.R, ModifierKeys.Control, "Ctrl+R"));
requery = new RoutedUICommand(
"Requery", "Requery", typeof(DataCommands), inputs);
}

public static RoutedUICommand Requery
{
get { return requery; }
}
}

}
技术图片

备注:我们主要看DataCommands类

         InputGestureCollection 表示 输入手势的一个集合,里面放入InputGesture类型的手势,手势好别扭,俗语话吧叫手段,就是输入手段,例如键盘输入啊,鼠标输入等,这里KeyGesture懂英语的看字面就知道是键盘手段了,

new KeyGesture(Key.R, ModifierKeys.Control, "Ctrl+R"),这里一看,26个字母中是R键,ModifierKeys.Control是 ctrl 键,加起来就是Ctrl+R,后面那个应该是用来显示在菜单中后面的那个快捷键提示吧,ModifierKeys里面还有Shift,Alt,Windows,None等,自己试试就知道了,接下来就是向路由命令里面填值了,就是这个命令是什么快捷键啊,什么什么的,参数什么意思,你在vs中鼠标移上去,会有说明的,潜移默化(举一反三)一下吧,你们!

 

前台这样调用这个命令,因为以前我们都是调用系统的,这次是自己写的命令吧

前台页面

技术图片
<Window x:Class="Commands.CustomCommand"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Commands" Height="300" Width="300"
xmlns:local="clr-namespace:Commands"
>
<Window.CommandBindings>
<CommandBinding Command="local:DataCommands.Requery"
Executed="RequeryCommand"/>
</Window.CommandBindings>
<Grid>
<Button Margin="5" Command="local:DataCommands.Requery">Requery</Button>
</Grid>
</Window>
技术图片

直接在把那个Command后面的值不用系统的,用自己的,自己潜移默化吧,不懂的,看看前两章内容吧

     

    

   

潜移默化学会WPF--Command(命令)学习(三) - AYUI框架 - 博客园

标签:turn   send   man   idt   rip   xmlns   microsoft   win   none   

原文地址:https://www.cnblogs.com/lonelyxmas/p/10459044.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!