Ninject と MVVMLight を使用します。viewmodel への TransientScope バインディングの使用。
ビューがなくなると、ビューモデルはスコープから外れます。
ビューモデルをクリーンアップするトリガーは何ですか...登録解除する必要がある登録済みイベントがいくつかあります。
ビューのアンロードイベントで EventToCommand を使用できますが、Ninject MVVMLight の方法でそれを行う方法を学びたいです:)ドキュメントを含め、どこにも見つけることができる例はありません。
ViewModelLocator
public class ViewModelLocator
{
//CONSTRUCTOR
static ViewModelLocator()
{
Kernel = new StandardKernel(new DataViewsModule());
}
//PRIVATE FIELDS
private static IKernel Kernel;
//PUBLIC PROPERTIES
public LiveDataViewModel LiveDataViewModel { get { return Kernel.Get<LiveDataViewModel>(); } }
/// <summary>
/// Cleans up all the resources.
/// </summary>
public static void Cleanup()
{
}
}
NinjectModule
class DataViewsModule : NinjectModule
{
public override void Load()
{
//View Models
Bind<DataViewsViewModel>().ToSelf().InSingletonScope();
Bind<LiveDataViewModel>().ToSelf().InTransientScope();
}
}
ビューのコンストラクタ:
public LiveDataView()
{
InitializeComponent();
Unloaded += (s, e) => ViewModelLocator.Cleanup();
}
以下は、ViewModelLocator Cleanup メソッドを呼び出すビューのアンロード イベントです。この一時的なビューモデルをクリーンアップするにはどうすればよいですか?