###前提・実現したいこと
Xamarin.FormsでMVVMパターンを用いて、アプリを作成しています。
「CmdStartコマンドがバインドされているボタン押下時に、次のページ(Page2)に遷移する」という処理をしたいのですが、Commandクラスに記述していいものなのかがわかりません。
UIと切り離すという意味でMVVMパターンがあるとすると、Commandにはなにを記述すればいいのでしょうか?
###ViewModelクラス
public class PageViewModel : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged = delegate { }; public ICommand CmdStart { get; set; } public PageViewModel() { this.CmdStart = new CmdStart(this); } protected virtual void OnPropertyChanged(string propertyName) { this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } }
###Commandクラス
public class CmdStart : ICommand { public event EventHandler CanExecuteChanged; private PageViewModel _vm; public CmdStart(PageViewModel vm) { this._vm = vm; } public bool CanExecute(object parameter) { return true; } public void Execute(object parameter) { this.ExecuteStart(); } private void ExecuteStart() { App.Current.MainPage.Navigation.PushAsync(new Page2()); }
###補足情報(言語/FW/ツール等のバージョンなど)
開発環境:VisualStudio For Mac COMMUNITY
開発言語:C#
Xamarin.Formsをフレームワークとして使用しております。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/09/10 22:42
2017/09/11 07:15
2017/09/11 07:22
2017/09/11 11:43