当前位置: 首页>>代码示例>>C#>>正文


C# ICommand.CanExecute方法代码示例

本文整理汇总了C#中ICommand.CanExecute方法的典型用法代码示例。如果您正苦于以下问题:C# ICommand.CanExecute方法的具体用法?C# ICommand.CanExecute怎么用?C# ICommand.CanExecute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ICommand的用法示例。


在下文中一共展示了ICommand.CanExecute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateAndAddButton

        /// <summary>
        /// Creates a button and adds it to an application bar.
        /// </summary>
        /// <param name="appBar"></param>
        /// <param name="iconFilenameRelative"></param>
        /// <param name="command"></param>
        /// <param name="text"></param>
        /// <returns></returns>
        public static ApplicationBarIconButton CreateAndAddButton(this IApplicationBar appBar, string iconFilenameRelative, ICommand command, string text)
        {
            ApplicationBarIconButton btn = new ApplicationBarIconButton(new Uri("/icons/" + iconFilenameRelative, UriKind.Relative));

            // First-time values.
            btn.IsEnabled = command.CanExecute(btn);
            btn.Text = text;

            // Adds click handler to execute the command upon click.
            btn.Click += (o, e) =>
            {
                if (command.CanExecute(btn))
                {
                    command.Execute(btn);
                }
            };

            // Adds CanExecute changed handler.
            command.CanExecuteChanged += (o, e) =>
            {
                btn.IsEnabled = command.CanExecute(btn);
            };

            // Adds the button.
            appBar.Buttons.Add(btn);

            return btn;
        }
开发者ID:chier01,项目名称:WF.Player.WinPhone,代码行数:36,代码来源:ShellExtensions.cs

示例2: CreateAndAddMenuItem

        /// <summary>
        /// Creates a menu item and adds it to an application bar.
        /// </summary>
        /// <param name="appBar"></param>
        /// <param name="command"></param>
        /// <param name="text"></param>
        /// <returns></returns>
        public static ApplicationBarMenuItem CreateAndAddMenuItem(this IApplicationBar appBar, ICommand command, string text)
        {
            ApplicationBarMenuItem mi = new ApplicationBarMenuItem(text);

            // First-time values.
            mi.IsEnabled = command.CanExecute(mi);

            // Adds click handler to execute the command upon click.
            mi.Click += (o, e) =>
            {
                if (command.CanExecute(mi))
                {
                    command.Execute(mi);
                }
            };

            // Adds CanExecute changed handler.
            command.CanExecuteChanged += (o, e) =>
            {
                mi.IsEnabled = command.CanExecute(mi);
            };

            // Adds the button.
            appBar.MenuItems.Add(mi);

            return mi;
        }
开发者ID:chier01,项目名称:WF.Player.WinPhone,代码行数:34,代码来源:ShellExtensions.cs

示例3: Include

		public void Include (ICommand command)
		{
			command.CanExecuteChanged += (s, e) => {
				if (command.CanExecute (null))
					command.Execute (null);
			};
		}
开发者ID:fatelord,项目名称:chgk,代码行数:7,代码来源:LinkerPleaseInclude.cs

示例4: Execute

 public static void Execute(ICommand command, object parameter, IInputElement target)
 {
     var routedCmd = command as RoutedCommand;
     if (routedCmd != null && routedCmd.CanExecute(parameter, target))
         routedCmd.Execute(parameter, target);
     else if (command != null && command.CanExecute(parameter))
         command.Execute(parameter);
 }
开发者ID:Mikolaytis,项目名称:Mikolaytis,代码行数:8,代码来源:CommandHelper.cs

示例5: CanExecute

        public static bool CanExecute(ICommand command, object parameter, IInputElement target)
        {
            if (command == null)
                return false;

            var routedCommand = command as RoutedCommand;
            return routedCommand?.CanExecute(parameter, target) ?? command.CanExecute(parameter);
        }
开发者ID:LionFree,项目名称:Cush,代码行数:8,代码来源:CommandHelper.cs

示例6: ExecuteCommand

        public static void ExecuteCommand(
			ICommand command, 
			GestureArgs parameter = null)
        {
            if (command != null &&
                command.CanExecute (parameter)) {
                command.Execute (parameter);
            }
        }
开发者ID:pragmaticlogic,项目名称:athena,代码行数:9,代码来源:GestureUtil.cs

示例7: CanExecuteCommand

		public static bool CanExecuteCommand(ICommand command, object parameter, IInputElement target)
		{
			if (command == null)
				return false;
			RoutedCommand routed = command as RoutedCommand;
			if (routed != null)
				return routed.CanExecute(parameter, target);
			return command.CanExecute(parameter);
		}
开发者ID:VladMorzhanov,项目名称:Study-Csharp-Projects-2015,代码行数:9,代码来源:CommandTool.cs

示例8: Run

        public void Run()
        {
            var objBindable = new DataObject();

            var myBinding = new Binding("Amount", objBindable, "Amount", true, DataSourceUpdateMode.OnPropertyChanged);

            var objWithBinding = new DataObjectWithBindable();
            objWithBinding.PropertyChanged += (sender, args) =>
            {
                Console.WriteLine(args.PropertyName);
            };
            objWithBinding.DataBindings.Add(myBinding);

            objBindable.Amount = 30 + 10;
            objBindable.Message = "test";

            objWithBinding.Amount = 55;

            objBindable.Amount = 54;

            HiButtonCommand = new RelayCommand(
                ShowMessage,
                param =>
                    {
                        var t = (DataObject)param;
                        return t.Amount < 10;
                    });

            HiButtonCommand.CanExecuteChanged += HiButtonCommandOnCanExecuteChanged;

            objBindable.Amount = 9;

            if (HiButtonCommand.CanExecute(objBindable))
            {
                HiButtonCommand.Execute(objBindable);
            }

            objBindable.Amount = 11;

            if (HiButtonCommand.CanExecute(objBindable))
            {
                HiButtonCommand.Execute(objBindable);
            }
        }
开发者ID:prachwal,项目名称:DataBindingProject,代码行数:44,代码来源:Program.cs

示例9: ExecuteRefreshCommand

        protected virtual void ExecuteRefreshCommand(ICommand command)
        {
            if (command == null)
                return;

            if (!command.CanExecute(null))
                return;

            command.Execute(null);
        }
开发者ID:lothrop,项目名称:MvvmCross-AndroidSupport,代码行数:10,代码来源:MvxSwipeRefreshLayout.cs

示例10: ExecuteCommand

        /// <summary>
        /// Attempts to executes a command command.
        /// </summary>
        /// <param name="cmd">The command to be executed.</param>
        /// <param name="parameter">The command parameter.</param>
        /// <returns>True if the command was executed; otherwise false.</returns>
        private static bool ExecuteCommand(ICommand cmd, object parameter)
        {
            if (cmd != null && cmd.CanExecute(parameter))
            {
                cmd.Execute(parameter);
                return true;
            }

            return false;
        }
开发者ID:adamwyss,项目名称:slexplorer,代码行数:16,代码来源:InputBindings.cs

示例11: CommandPropertyItem

        public CommandPropertyItem(PropertyDescriptor property, object instance)
            : base(property, instance)
        {
            _command = property.GetValue(instance) as ICommand;
            if (_command != null)
            {
                _command.CanExecuteChanged += CanExecuteChanged;
            }

            _executeCommand = new Command<object>(o => _command.Execute(GetCommandParameter()), o => _command != null && _command.CanExecute(GetCommandParameter()));
        }
开发者ID:bdurrani,项目名称:WPF-Inspector,代码行数:11,代码来源:CommandPropertyItem.cs

示例12: ChainCommand

        public ChainCommand(ICommand postCommand, Action<object> execute, Func<object, bool> canExecute = null)
        {
            if (canExecute == null) canExecute = x => true;

            _execute = x => {
                execute(x);
                postCommand.Execute(x);
            };

            _canExecute = x => canExecute(x) && postCommand.CanExecute(x);
        }
开发者ID:Visic,项目名称:CSharpUtility,代码行数:11,代码来源:ChainCommand.cs

示例13: JSCommand

  public JSCommand(HTMLViewContext context, IJavascriptToCSharpConverter converter, ICommand command)
  {
      _JavascriptToCSharpConverter = converter;
      _HTMLViewContext = context;
      _Command = command;
 
      try
      {
          _InitialCanExecute = _Command.CanExecute(null);
      }
      catch { }
  }
开发者ID:David-Desmaisons,项目名称:MVVM.CEF.Glue,代码行数:12,代码来源:JSCommand.cs

示例14: ExecuteCommandOnItem

        protected virtual void ExecuteCommandOnItem(ICommand command)
        {
            if (command == null)
                return;

            var item = DataContext;
            if (item == null)
                return;

            if (!command.CanExecute(item))
                return;

            command.Execute(item);
        }
开发者ID:lothrop,项目名称:MvvmCross-AndroidSupport,代码行数:14,代码来源:MvxRecyclerViewHolder.cs

示例15: ExecuteCommand

 private void ExecuteCommand(ICommand command, object parameter, IInputElement target)
 {
     RoutedCommand command2 = command as RoutedCommand;
     if (command2 != null)
     {
         if (command2.CanExecute(parameter, target))
         {
             command2.Execute(parameter, target);
         }
     }
     else if (command.CanExecute(parameter))
     {
         command.Execute(parameter);
     }
 }
开发者ID:GemHu,项目名称:ExportManager,代码行数:15,代码来源:UcProjectInfo.xaml.cs


注:本文中的ICommand.CanExecute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。