Exemple #1
0
        /// <summary>
        /// Frame to hold the actual work on a background thread. Should only be called by a command
        /// </summary>
        /// <param name="action">Actual work to be done</param>
        private void DoBGAction(QuirkyAction action)
        {
            if (mBusy == true) return;
            mBusy = true;

            var bw = new BackgroundWorker { WorkerReportsProgress = true };
            bw.DoWork += (s, e) => action(bw);
            bw.RunWorkerCompleted += (s, e) =>
            {
                mBusy = false;
                Progress = 0;
                Status = string.Empty;
            };
            bw.ProgressChanged += (s, e) =>
            {
                Progress = e.ProgressPercentage;
                if (e.UserState != null && e.UserState.GetType() == typeof(string))
                    Status = e.UserState.ToString();
            };

            bw.RunWorkerAsync();
        }
Exemple #2
0
 private void BindCommand(MainViewModel source, Expression<Func<MainViewModel, ICommand>> outExpr, QuirkyAction input)
 {
     var expr = (MemberExpression)outExpr.Body;
     var prop = (PropertyInfo)expr.Member;
     var command = new CustomCommand
     {
         CanExecuteAction = o => !source.mBusy,
         ExecuteAction = o => source.DoBGAction(input)
     };
     prop.SetValue(source, command, null);
 }
Exemple #3
0
 private CommandsAndActions CA(Expression<Func<MainViewModel, ICommand>> property, QuirkyAction command)
 {
     return new CommandsAndActions(property, command);
 }
Exemple #4
0
 public CommandsAndActions(Expression<Func<MainViewModel, ICommand>> property, QuirkyAction command)
 {
     Property = property;
     Command = command;
 }