Beispiel #1
0
        internal UICommand(ClientCommand command, Type ownerType, InputGestureCollection gestures)
            : base(command.Meta.Label ?? string.Empty, command.Meta.Name, ownerType, gestures)
        {
            if (command == null) { throw new ArgumentNullException("command"); }

            this._command = command;
        }
Beispiel #2
0
        protected override FrameworkElement CreateCommandUI(ClientCommand cmd)
        {
            var textBox = CreateTextBox(cmd);

            if (this.TriggerMode == TextBoxCommandTriggerMode.EnterPressed)
            {
                //在textBox上按下回车时,执行命令。
                textBox.KeyDown += (o, e) =>
                {
                    if (e.Key == Key.Enter)
                    {
                        cmd.TryExecute(textBox);
                    }
                };
            }
            else
            {
                textBox.TextChanged += (o, e) =>
                {
                    cmd.TryExecute(textBox);
                };
            }

            return textBox;
        }
Beispiel #3
0
        /// <summary>
        /// 编程时可使用的名字,
        /// “由于 Name 可能包含一些奇怪的字符,所以不能直接赋值给控件的 Name”。
        /// </summary>
        internal static string GetProgrammingName(ClientCommand command)
        {
            string result = Regex.Replace(command.Meta.Name, @"[^a-zA-Z_]", "_");

            result = result.Insert(0, "cmd_");
            return(result);
        }
Beispiel #4
0
        protected override FrameworkElement CreateCommandUI(ClientCommand cmd)
        {
            var listSource = cmd as IDataSelectorCommand;

            if (listSource == null)
            {
                throw new InvalidProgramException("命令必须继承 DataSelectorCommand<T> 类。");
            }

            var item = this.CreateMenuItem(cmd);

            item.Header = this.SingleMeta.Label;

            item.ItemsSource = listSource.DataSource;
            item.Click      += (o, e) =>
            {
                //当点击的是 ItemsSource 绑定生成的 MenuItem 时,开始执行事件。
                if (e.OriginalSource != e.Source)
                {
                    var itemSelected = (e.OriginalSource as MenuItem).Header.ToString();
                    listSource.SetSelectedItem(itemSelected);
                    cmd.TryExecute(item);
                }
            };

            return(item);
        }
Beispiel #5
0
        private static void OnCommandCreated(ClientCommand cmd)
        {
            var handler = CommandCreated;

            if (handler != null)
            {
                handler(null, new InstanceEventArgs <ClientCommand>(cmd));
            }
        }
Beispiel #6
0
        internal UICommand(ClientCommand command, Type ownerType, InputGestureCollection gestures) :
            base(command.Meta.Label ?? string.Empty, command.Meta.Name, ownerType, gestures)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            this._command = command;
        }
Beispiel #7
0
            protected override FrameworkElement CreateCommandUI(ClientCommand cmd)
            {
                var textBox = CreateTextBox(cmd);

                //在textBox上按下回车时,执行命令。
                textBox.KeyDown += (o, e) =>
                {
                    if (e.Key == Key.Enter)
                    {
                        cmd.TryExecute(textBox);

                        textBox.Text = string.Empty;
                    }
                };

                return textBox;
            }
Beispiel #8
0
 /// <summary>
 /// 编程时可使用的名字,
 /// “由于 Name 可能包含一些奇怪的字符,所以不能直接赋值给控件的 Name”。
 /// </summary>
 internal static string GetProgrammingName(ClientCommand command)
 {
     string result = Regex.Replace(command.Meta.Name, @"[^a-zA-Z_]", "_");
     result = result.Insert(0, "cmd_");
     return result;
 }
Beispiel #9
0
 /// <summary>
 /// 设置文件框输入值。
 /// </summary>
 /// <param name="command"></param>
 /// <param name="value"></param>
 public static void SetTextBoxParameter(ClientCommand command, string value)
 {
     command.SetExtendedProperty(TextBox, value);
 }
Beispiel #10
0
 /// <summary>
 /// 获取文件框输出值。
 /// </summary>
 /// <param name="command"></param>
 /// <returns></returns>
 public static string GetTextBoxParameter(ClientCommand command)
 {
     return command.GetPropertyOrDefault<string>(TextBox);
 }
Beispiel #11
0
        /// <summary>
        /// 为运行时的Command生成一个菜单项
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        protected MenuItem CreateMenuItem(ClientCommand command)
        {
            MenuItem menuItem = new MenuItem();
            menuItem.CommandParameter = this.Context.CommandArg;
            MenuItemCommand.SetCommand(menuItem, command.UICommand);

            return menuItem;
        }
Beispiel #12
0
 private static void OnCommandCreated(ClientCommand cmd)
 {
     var handler = CommandCreated;
     if (handler != null) { handler(null, new InstanceEventArgs<ClientCommand>(cmd)); }
 }
Beispiel #13
0
        /// <summary>
        /// 为一个运行时的 Command 生成 TextBox 控件。
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        protected static TextBox CreateTextBox(ClientCommand command)
        {
            var textBox = new TipTextBox()
            {
                Width = 150,
                VerticalAlignment = VerticalAlignment.Center,
                Margin = new Thickness(2),
                EmptyValue = command.Label,
                ToolTip = command.Meta.ToolTip.Translate()
            };

            //当TextBox的值改变时,通知命令进行新的输入值
            textBox.TextChanged += (o, e) =>
            {
                var txt = textBox.Text;
                if (txt == textBox.EmptyValue) { txt = string.Empty; }
                SetTextBoxParameter(command, txt);
            };

            //支持UI Test
            AutomationProperties.SetName(textBox, command.Label);

            return textBox;
        }
Beispiel #14
0
 protected override FrameworkElement CreateCommandUI(ClientCommand command)
 {
     return this.CreateMenuItem(command);
 }
Beispiel #15
0
 /// <summary>
 /// 这个类的子类实现此方法,来生成具体的命令与控件。
 /// </summary>
 /// <returns></returns>
 protected abstract FrameworkElement CreateCommandUI(ClientCommand command);
Beispiel #16
0
 internal static CommandBinding CreateCommandBinding(ClientCommand cmd)
 {
     return(new CommandBinding(cmd.UICommand, CommandBindingExecuted, CommandBindingCanExecute));
 }
Beispiel #17
0
        /// <summary>
        /// 为运行时的Command生成一个按钮
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        protected Button CreateButton(ClientCommand command)
        {
            var btn = new Button();
            btn.CommandParameter = this.Context.CommandArg;
            ButtonCommand.SetCommand(btn, command.UICommand);

            return btn;
        }
Beispiel #18
0
 internal static CommandBinding CreateCommandBinding(ClientCommand cmd)
 {
     return new CommandBinding(cmd.UICommand, CommandBindingExecuted, CommandBindingCanExecute);
 }