LoginSignup
1
0

More than 5 years have passed since last update.

ViewModelBaseクラス(MVVM Light Toolkit リファレンス)

Last updated at Posted at 2018-10-15

ViewModelBase

概要

public abstract class ViewModelBase : ObservableObject, ICleanup
  • MVVMパターンのビューモデルの基底クラスに使う。
名前空間
  • GalaSoft.MvvmLight

アセンブリ

  • GalaSoft.MvvmLight

メソッド

コンストラクター

コンストラクター
public ViewModelBase()
public ViewModelBase(GalaSoft.MvvmLight.Messaging.IMessenger messenger)
概要
  • 引数をMessengerInstanceプロパティに設定する。
  • 引数がない場合、MessengerInstanceプロパティにnullを設定する。

Broadcast

Broadcast
protected virtual void Broadcast<T>(T oldValue, T newValue, string propertyName)
概要
  • プロパティ名(propertyName)、元の値(oldValue)、新しい値(newValue)を指定し、PropertyChangedMessageを送る。

Cleanup

Cleanup
public virtual void Cleanup()
概要
  • ICleanupインターフェイスの実装。
  • MessengerInstanceからこのインスタンスの登録を解除する。
  • その他のクリーンアップ処理が必要な場合は、このメソッドをオーバーライドし、オーバーライドしたメソッドからこのメソッドを呼ぶこと。

RaisePropertyChanged

RaisePropertyChanged
public virtual void RaisePropertyChanged<T>(string propertyName = null, T oldValue = null, T newValue = null, bool broadcast = False)
public virtual void RaisePropertyChanged<T>(System.Linq.Expressions.Expression<System.Func<T>> propertyExpression, T oldValue, T newValue, bool broadcast)
概要
  • 指定したプロパティを引数にして、RaisePropertyChangedメソッドを呼ぶ。
  • broadcasttrueの場合、Broadcastメソッドを呼ぶ。
例外
  • System.ArgumentException: 指定した名前を持つプロパティが存在しない。

Set

Set
protected bool Set<T>(string propertyName, ref T field, T newValue = null, bool broadcast = False)
protected bool Set<T>(System.Linq.Expressions.Expression<System.Func<T>> propertyExpression, ref T field, T newValue, bool broadcast)
protected bool Set<T>(ref T field, T newValue = null, bool broadcast = False, string propertyName = null)
概要
  • fieldnewValueを代入する。
  • fieldの値が変化したら、propertyNamepropertyExpressionを引数にしてRaisePropertyChangedメソッドを呼ぶ。
  • broadcasttrueの場合、Broadcastメソッドを呼ぶ。
戻り値
  • fieldの値が変化したらtrue、変化しなかったらfalseを戻す。
例外
  • System.ArgumentException: 指定した名前を持つプロパティが存在しない。

プロパティ

IsInDesignMode

IsInDesignMode
public bool IsInDesignMode { get; }
概要
  • デザイン・モード(Visual StudioやBlendで編集中である状態)かどうかを戻す。

IsInDesignModeStatic

IsInDesignModeStatic
public static bool IsInDesignModeStatic { get; }
概要
  • デザイン・モード(Visual StudioやBlendで編集中である状態)かどうかを戻す。

MessengerInstance

MessengerInstance
protected GalaSoft.MvvmLight.Messaging.IMessenger MessengerInstance { get; set; }
概要
  • Broadcastメソッドが使うIMessengerインターフェイスのインスタンス。
  • nullが設定された場合、MessengerクラスのDefaultプロパティを戻す。

参照

1
0
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
1
0