示例#1
0
 public MainViewModel()
 {
     if (POCOViewModelExtensions.IsInDesignMode(this))
     {
         return;
     }
     AppUIManager.Application.MainWindow.WindowState = System.Windows.WindowState.Maximized;
 }
示例#2
0
 public static bool IsInDesignMode()
 {
     if (Application.MainWindow?.DataContext != null)
     {
         return(POCOViewModelExtensions.IsInDesignMode(Application.MainWindow.DataContext));
     }
     return(true);
 }
 public LoginViewModel()
 {
     if (POCOViewModelExtensions.IsInDesignMode(this))
     {
         return;
     }
     GlobalVar.Users.CollectionChanged += Users_CollectionChanged;
     SelectedUser = GlobalVar.Users.FirstOrDefault();
 }
        protected internal IDelegateCommand GetCommand(Expression <Action> commandMethodExpression)
        {
            if (IsPOCOViewModel)
            {
                return(POCOViewModelExtensions.GetCommandCore(this, commandMethodExpression));
            }
            var method  = ExpressionHelper.GetMethod(commandMethodExpression);
            var command = GetCommandCore(method);

            return((IDelegateCommand)command);
        }
示例#5
0
 protected internal void RaiseCanExecuteChanged(Expression <Action> commandMethodExpression)
 {
     if (IsPOCOViewModel)
     {
         POCOViewModelExtensions.RaiseCanExecuteChangedCore(this, commandMethodExpression);
     }
     else
     {
         ((IDelegateCommand)commandProperties[ExpressionHelper.GetMethod(commandMethodExpression)]
          .GetValue(this)
         ).RaiseCanExecuteChanged();
     }
 }
        public void BindTaskbarThumbButtonInfoCommand()
        {
            VM vm = VM.Create();

            RealWindow.DataContext = vm;
            TaskbarButtonService   taskbarServiceImpl = new TaskbarButtonService();
            TaskbarThumbButtonInfo bt = new TaskbarThumbButtonInfo();

            BindingOperations.SetBinding(bt, TaskbarThumbButtonInfo.CommandProperty, new Binding("DoCommand"));
            taskbarServiceImpl.ThumbButtonInfos.Add(bt);
            Interaction.GetBehaviors(RealWindow).Add(taskbarServiceImpl);
            EnqueueShowRealWindow();
            Assert.AreEqual(POCOViewModelExtensions.GetCommand(vm, x => x.Do()), bt.Command);
        }
示例#7
0
 /// <summary>
 /// Initializes a new instance of the MainViewModel class.
 /// </summary>
 protected MainViewModel()
 {
     URL = "https://library.princeton.edu/special-collections/sites/default/files/Creating_PDFA.pdf";
     if (POCOViewModelExtensions.IsInDesignMode(this))
     {
         Path         = "-";
         Progress     = 60;
         DownloadTime = "-";
     }
     else
     {
         stopWatch = new Stopwatch();
     }
 }
        protected internal IAsyncCommand GetAsyncCommand(Expression <Func <System.Threading.Tasks.Task> > commandMethodExpression)
        {
            if (IsPOCOViewModel)
            {
                return(POCOViewModelExtensions.GetAsyncCommandCore(this, commandMethodExpression));
            }
            var method  = ExpressionHelper.GetMethod(commandMethodExpression);
            var command = GetCommandCore(method);

            if (!(command is IAsyncCommand))
            {
                throw new CommandAttributeException(ViewModelSourceException.Error_CommandNotAsync);
            }
            return((IAsyncCommand)command);
        }
示例#9
0
        TCommand GetCommandCore <TCommand>(LambdaExpression methodExpression) where TCommand : class, IDelegateCommand
        {
            if (IsPOCOViewModel)
            {
                return(POCOViewModelExtensions.GetCommandCore <TCommand>(this, methodExpression));
            }
            var method = ExpressionHelper.GetMethod(methodExpression);

            if (method == null)
            {
                throw new CommandAttributeException(string.Format(ViewModelSourceException.Error_CommandNotFound, method.Name + CommandNameSuffix));
            }
            CommandProperty commandProperty;

            if (commandProperties.TryGetValue(method, out commandProperty))
            {
                return((TCommand)commandProperty.GetValue(this));
            }
            throw new CommandAttributeException(string.Format(ViewModelSourceException.Error_CommandNotFound, method.Name + CommandNameSuffix));
        }
 protected void OnPatronIDChanged() => POCOViewModelExtensions.RaisePropertyChanged(this, vm => vm.ExtraTabVisibility);