コード例 #1
0
ファイル: TaskViewModel.cs プロジェクト: xxblancxx/ForecastIt
        public TaskViewModel()
            {

                AddTask = new RoutedCommand(CreateTasked);
                

        }
コード例 #2
0
 public CommandBinding(RoutedCommand command, ExecuteEventHandler executeEventHandler,
                       QueryEnabledEventHandler queryEnabledEventHandler)
 {
   _command = command;
   _executeEventHandler = executeEventHandler;
   _queryEnabledEventHandler = queryEnabledEventHandler;
 }
コード例 #3
0
        public OrderViewModel()
        {
            NewOrders = new RoutedCommand(NewOrder);
            AddOrder = new RoutedCommand(CreateOrder);
            UpdateOrder = new RoutedCommand(EditOrder);
            DeleteOrder = new RoutedCommand(RemoveOrder);

            LoadOrders();
            Order = new Order();
        }
コード例 #4
0
 public CommandBinding(RoutedCommand command, ExecuteEventHandler executeEventHandler)
   : this(command, executeEventHandler, null) {}
コード例 #5
0
        public static void RemoveCommandExecutedHandler(this CommandBindingCollection collection, RoutedCommand command, ExecutedRoutedEventHandler handler)
        {
            CommandBinding binding = GetBinding(collection, command);

            if (binding != null)
            {
                binding.Executed -= handler;
            }
        }
コード例 #6
0
 public CommandBinding(RoutedCommand command) : this(command, null) {}
コード例 #7
0
        public static void RemoveCommandPreviewCanExecuteHandler(this CommandBindingCollection collection, RoutedCommand command, CanExecuteRoutedEventHandler handler)
        {
            CommandBinding binding = GetBinding(collection, command);

            if (binding != null)
            {
                binding.PreviewCanExecute -= handler;
            }
        }
コード例 #8
0
        public static void AddCommandExecutedHandler(this CommandBindingCollection collection, RoutedCommand command, ExecutedRoutedEventHandler handler)
        {
            CommandBinding binding = GetOrCreateBinding(collection, command);

            // Remove the handler if it already exist
            binding.Executed -= handler;
            binding.Executed += handler;
        }
コード例 #9
0
        public static void AddCommandPreviewCanExecuteHandler(this CommandBindingCollection collection, RoutedCommand command, CanExecuteRoutedEventHandler handler)
        {
            CommandBinding binding = GetOrCreateBinding(collection, command);

            // Remove the handler if it already exist
            binding.PreviewCanExecute -= handler;
            binding.PreviewCanExecute += handler;
        }
コード例 #10
0
ファイル: thumbviewer.cs プロジェクト: systembugtj/bookasa
 private static RoutedCommand DeclareCommand(ref RoutedCommand command,
                                             string commandDebugName)
 {
     return(DeclareCommand(ref command, commandDebugName, null));
 }
コード例 #11
0
        public Start()
        {
            InitializeComponent();
            //获取MC类
            MC mc = MC.GetMC();

            //将Name绑定到mc的Name属性
            GameName.SetBinding(TextBox.TextProperty, new Binding("Name")
            {
                Source = mc, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged, Mode = BindingMode.TwoWay
            });
            //设置Vers的源由MCseting提供
            Vers.ItemsSource = MCSetting.AllVer;
            //创建启动路由命令
            RoutedCommand StartCommand = new RoutedCommand();

            //设置命令快捷键
            StartCommand.InputGestures.Add(new KeyGesture(Key.S, ModifierKeys.Alt));
            //创造命令绑定
            CommandBinding StartCommandBinding = new CommandBinding(StartCommand);

            //将Ver绑定
            Vers.SetBinding(ComboBox.SelectedItemProperty, new Binding("Ver")
            {
                Source = mc, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged, Mode = BindingMode.TwoWay
            });
            //设置什么时候命令可以执行
            StartCommandBinding.CanExecute += (s, e) =>
            {
                if (mc.IsReady())
                {
                    e.CanExecute = true;
                }
                else
                {
                    e.CanExecute = false;
                }
                e.Handled = true;
            };
            //设置执行的内容
            StartCommandBinding.Executed += (s, e) =>
            {
                var setting = MCsettingJSONModel.GetConfig;
                setting.Name = mc.Name;
                var mcsetting = MCSetting.GetSetting();
                setting.JavaPath             = mcsetting.JavaPath;
                setting.MaxRam               = mcsetting.MaxRam;
                setting.MCVer                = mc.Ver.Name;
                MCsettingJSONModel.GetConfig = setting;
                try
                {
                    Load.Visibility = Visibility.Visible;
                    mc.Start();
                    Environment.Exit(0);
                }
                catch (ApplicationException ex)
                {
                    var r = ModernDialog.ShowMessage($"在启动时出现了异常:{Environment.NewLine}信息:{ex.Message}{Environment.NewLine}源:{ex.Source}{Environment.NewLine}在方法{ex.TargetSite}中{Environment.NewLine}堆栈跟踪:{ex.StackTrace}", "异常", MessageBoxButton.YesNo);
                    if (r == MessageBoxResult.Yes)
                    {
                        Environment.FailFast("因异常而终止");
                    }
                }
                catch (System.IO.DirectoryNotFoundException ex)
                {
                    var r = ModernDialog.ShowMessage($"在启动时出现了异常:{Environment.NewLine}信息:{ex.Message}{Environment.NewLine}源:{ex.Source}{Environment.NewLine}在方法{ex.TargetSite}中{Environment.NewLine}堆栈跟踪:{ex.StackTrace}", "异常", MessageBoxButton.YesNo);
                    if (r == MessageBoxResult.Yes)
                    {
                        Environment.FailFast("因异常而终止");
                    }
                }
                catch (System.IO.FileNotFoundException ex)
                {
                    var r = ModernDialog.ShowMessage($"在启动时出现了异常:{Environment.NewLine}信息:{ex.Message}{Environment.NewLine}源:{ex.Source}{Environment.NewLine}在方法{ex.TargetSite}中{Environment.NewLine}堆栈跟踪:{ex.StackTrace}", "异常", MessageBoxButton.YesNo);
                    if (r == MessageBoxResult.Yes)
                    {
                        Environment.FailFast("因异常而终止");
                    }
                }
                finally
                {
                    Load.Visibility = Visibility.Hidden;
                }
                e.Handled = true;
            };
            //添加命令到控件
            Starter.Command = StartCommand;
            //添加命令绑定
            Starter.CommandBindings.Add(StartCommandBinding);
        }