LoginSignup
0
1

More than 5 years have passed since last update.

Prism入門(1)

Last updated at Posted at 2017-07-07

Prismインストール

パッケージマネージャーコンソール
PM> Install-Package Prism

ViewModel

クラスの作成

BindableBaseを継承する。

sample.cs
class CalcViewModel :BindableBase
{
}

プロパティ

sample.cs
        private string _leftValue;
        public string LeftValue
        {
            get { return _leftValue; }
            set { this.SetProperty(ref this._leftValue, value); }
        }

コマンド

using Microsoft.Practices.Prism.Commands;

sample.cs
        private ICommand calcCommand;
        public ICommand CalcCommand
        {
            get { return this.calcCommand ?? (this.calcCommand = new DelegateCommand(CalcExecute, CanCalcExecute)); }
        }

        private bool CanCalcExecute()
        {
            return true;
        }

        private void CalcExecute()
        {
            // ロジックを書く
        }

コマンドの実行可否が変わったことを通知するには、DelegateCommandクラスのRaiseCanExecuteChangedメソッドを呼ぶ必要がある。
Prism6だとObservesPropertyメソッドが用意されている。

            get { return this.calcCommand ?? (this.calcCommand = new DelegateCommand(CalcExecute, CanCalcExecute)
                    .ObservesProperty(() => this.FOO)
                    .ObservesProperty(() => this.BAR)); }
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1