ViewModel の最初のアプローチを使用していると仮定すると、ISceens と Screen の実装を確認しましたか? 現在の Caliburn.Micro ダウンロードには、スクリーン コーディネーターを実装したデモ プロジェクト (SimpleMDI) が含まれています。
メイン ビューモデルのアクティブ化/非アクティブ化機能を使用して、「プロパティ」ビュー間の切り替えを処理できます。
メイン ビューモデルは、Caliburn が提供するConductor<T>.Collection.OneActive
、T が IScreen である場所の実装から派生する必要があります。これにより、メイン ビュー モデルは一度に 1 つの画面のみをアクティブにできます。
基本的に、「選択した項目」をメイン ビューモデルのプロパティにバインドすると、プロパティの変更通知を (NotifyOfPropertyChange を使用して) 監視し、何らかのルーチンを使用してどのビューに切り替えるかを決定できます。
Caliburn はビューをキャッシュしたままにし (Conductor で GetChildren を使用します)、ビューを切り替えることができるので、パフォーマンスを維持できます。
このようなものを使用して、データベースと利用可能なライブラリに基づいてコントロールを動的にインスタンス化します (CurrentView は実際にはカスタム タイプであり、実際にはビューではないため、私の例は少し混乱していることに注意してください。これは、コントロールを記述する単なるデータベース オブジェクトです)。が選択されています..おそらく変更する必要があります!)
public MainPageViewModel : Caliburn.Micro.Conductor<IScreen>.Collection.OneActive
{
#region Property Changed handler
public override void NotifyOfPropertyChange(string propertyName)
{
base.NotifyOfPropertyChange(propertyName);
// A property changed, update the views if it's the CurrentView property
UpdateViews(propertyName);
}
#endregion
private void UpdateViews(string propertyName)
{
// If the selected item in my list changes, it's bound to CurrentView and contains
// the fully qualified typename of the ViewModel that the items 'screen' should use
if (propertyName == "CurrentView")
{
// If the selected item changes we need to load the control or retrieve it from the
// control cache, making sure to update the cache and the active view dictionary
try
{
var controlType = Type.GetType(CurrentView.QualifiedTypeName, true);
// Check to see if the view is already loaded
var view = GetChildren().FirstOrDefault(x => x.GetType() == controlType);
// If it is, just activate it
if (view != null)
{
ActivateItem(view);
}
else
{
// Otherwise it's not loaded, load it and activate it
view = (IScreen)Activator.CreateInstance(controlType);
ActivateItem(view);
}
// etc...
}
}