Esiste una versione di RelayCommand, dal momento che CommandManager non è disponibile nelle app win8 metro?Comando di inoltro in windows 8 windows store app
7
A
risposta
4
Esiste una versione here.
using System;
using System.Diagnostics;
#if METRO
using Windows.UI.Xaml.Input;
using System.Windows.Input;
#else
using System.Windows.Input;
#endif
namespace MyToolkit.MVVM
{
#if METRO
public class RelayCommand : NotifyPropertyChanged, ICommand
#else
public class RelayCommand : NotifyPropertyChanged<RelayCommand>, ICommand
#endif
{
private readonly Action execute;
private readonly Func<bool> canExecute;
public RelayCommand(Action execute)
: this(execute, null) { }
public RelayCommand(Action execute, Func<bool> canExecute)
{
if (execute == null)
throw new ArgumentNullException("execute");
this.execute = execute;
this.canExecute = canExecute;
}
bool ICommand.CanExecute(object parameter)
{
return CanExecute;
}
public void Execute(object parameter)
{
execute();
}
public bool CanExecute
{
get { return canExecute == null || canExecute(); }
}
public void RaiseCanExecuteChanged()
{
RaisePropertyChanged("CanExecute");
if (CanExecuteChanged != null)
CanExecuteChanged(this, new EventArgs());
}
public event EventHandler CanExecuteChanged;
}
public class RelayCommand<T> : ICommand
{
private readonly Action<T> execute;
private readonly Predicate<T> canExecute;
public RelayCommand(Action<T> execute)
: this(execute, null)
{
}
public RelayCommand(Action<T> execute, Predicate<T> canExecute)
{
if (execute == null)
throw new ArgumentNullException("execute");
this.execute = execute;
this.canExecute = canExecute;
}
[DebuggerStepThrough]
public bool CanExecute(object parameter)
{
return canExecute == null || canExecute((T)parameter);
}
public void Execute(object parameter)
{
execute((T)parameter);
}
public void RaiseCanExecuteChanged()
{
if (CanExecuteChanged != null)
CanExecuteChanged(this, new EventArgs());
}
public event EventHandler CanExecuteChanged;
}
}
1
non ci sono implementazioni se ICommand fornito in metropolitana, anche se ci sono diverse versioni disponibili, come questo su CodeProject.
0
Prisma per le app di Windows Store è ora disponibile, che contiene DelegateCommand (che implementa ICommand), oltre a un'implementazione di OnPropertyChanged.
Problemi correlati
- 1. App Store Windows (Windows 8) e UWP
- 2. Windows 8 App Store Orientamento Smooth Change
- 3. Differenza tra Windows 8 Store App e Windows Phone Apps
- 4. Windows 8 Store - App di debug scaricata dal negozio
- 5. Windows App Store - Icona allungata
- 6. Ottieni nomi localizzati delle app di Windows Store installate in Windows 8
- 7. Le app di Windows 8 Store (Metro) funzionano in Windows 7 o XP?
- 8. Prevenire pixelated Immagini in Windows Store App
- 9. Etichetta in Windows 8 App
- 10. Aggiornamento dell'interfaccia utente di Windows Store App
- 11. Schermata di acquisizione di Windows store App
- 12. Posso utilizzare Awesomium in Windows Store App?
- 13. Impossibile utilizzare Trace.WriteLine in Windows App Store
- 14. Ingrandimento dell'immagine nelle app di Windows Store
- 15. App Store di Windows e F #
- 16. Memorizzazione di cookie Windows Store App
- 17. Python nelle app di Windows Store
- 18. Desktop App Converter/Invia a Windows Store
- 19. TreeView nell'app di Windows 8 store in XAML
- 20. Windows 8 App vuota + errore DEP0700
- 21. Utilizzo di SQLite3 in Windows 8 Javascript App
- 22. Dove le app di Windows Store memorizzano le impostazioni locali?
- 23. Simulazione di un acquisto di Windows 8 Store acquisto
- 24. Windows Store WebView Alternativa
- 25. Windows 8 Store WinRT notifica brindisi locale non mostrando
- 26. Windows Universal Platform è la sostituzione di WinRT di Windows 8 e app di Windows Phone?
- 27. Controllare a livello di codice l'aggiornamento di Windows Store App
- 28. Componenti di mapping gratuiti per le app di Windows Store?
- 29. Windows 8 e Windows Phone 8
- 30. Interfaccia a riga di comando di Windows 8 Simulator
Basta sottolineare che questo file non ha la classe 'NotifyPropertyChanged' a cui fa riferimento, e molte persone sapranno come ricrearlo, ma potrebbe essere utile includerlo per coloro che non lo fanno. –
@OwenJohnson 'NotifyPropertyChanged' trovato qui: https://mytoolkit.svn.codeplex.com/svn/Shared/MVVM/NotifyPropertyChanged.cs – mydogisbox
Vedere https://xp-dev.com/svn/mytoolkit/Shared/MVVM/ NotifyPropertyChanged.cs –