私はこれを理解しようとして失っているので、ここにお尋ねします。私は検索しましたが、それはすべて意味があるものですが、私の状況にも当てはまらないものです。OnActivateが呼び出されないのはなぜですか?
MVVM
とCaliburn.Micro
でWPF
を使用しています。私はConductor<Screen>.Collection.OnceActive
である対応するビューモデルとScreen
から継承している画面を持つシェルウィンドウを持っています。私はコンダクタのコンストラクタ内でActivateItem
を呼び出すと、後続の画面を表示しますが、画面は正しく表示されますが、画面のオーバーライドはOnActivate
となり、画面のIsActive
プロパティはFalse
に設定されません。これが唯一の私が指揮からActivateItem
を呼び出す非常に最初の時間に発生し
、すべての追加の呼び出しが正常にOnActivate
とOnDeactivate
を呼び出します。
これは私にとって意味をなさないもので、何が起こっているのか分かりません。私はソリューションをきれいにし、再構築し、再起動しましたが、それでも正常に動作しません。
親指揮
[Export]
public sealed class ShellViewModel : Conductor<Screen>.Collection.OneActive, IHandle<SimpleMessage>
{
private readonly DashboardViewModel m_Dash;
private readonly LoginViewModel m_Login;
private readonly IEventAggregator m_MsgBus;
[ImportingConstructor]
public ShellViewModel(DashboardViewModel dash, LoginViewModel login, IEventAggregator msgBus)
{
this.m_MsgBus = msgBus;
this.m_Dash = dash;
this.m_Login = login;
this.ActivateItem(this.m_Login);
}
protected override void OnActivate()
{
this.m_MsgBus.Subscribe(this); //called correctly
}
protected override void OnDeactivate(bool close)
{
this.m_MsgBus.Unsubscribe(this); //called correctly
}
public void Handle(SimpleMessage message)
{
switch (message)
{
case SimpleMessage.LoginSuccess:
this.ActivateItem(this.m_Dash);
break;
case SimpleMessage.Logout:
this.ActivateItem(this.m_Login);
break;
}
}
}
子画面
[Export]
public sealed class LoginViewModel : Screen
{
private readonly IEventAggregator m_MsgBus;
[ImportingConstructor]
public LoginViewModel(IEventAggregator msgBus)
{
this.m_MsgBus = msgBus;
}
protected override void OnActivate()
{
//NOT called the first time, but is called every other time
MessageBox.Show("ACTIVATE TEST");
}
protected override void OnDeactivate(bool close)
{
//NOT called the first time, but is called every other time
MessageBox.Show("DEACTIVATE TEST");
}
public void CmdLogin(string password)
{
this.m_MsgBus.PublishOnUIThread(SimpleMessage.LoginSuccess);
}
public string Username { get; set; }
public string Password { get; set; }
}
UPDATE
私は踏み入れることができるように、私はカリバーンマイクロソースをダウンロード:下記のコードがありますActivateItem
機能と何が起こっているかを参照してください。なんらかの理由で最初にActivateItem
を指揮者から呼び出すと指揮者のIsActive
プロパティはfalseに設定され、CaliburnはOnActivate
の呼び出しをスキップします。なぜ私の財産が偽であるのか分かりません。私の指揮はDisplayRootViewFor
を使用して作成され、その機能が設定されていないように見えるされたルートビューなのでIsActive
は、導体で偽の理由があるように見えます
ConductorBaseWithActiveItem.cs
protected virtual void ChangeActiveItem(T newItem, bool closePrevious) {
ScreenExtensions.TryDeactivate(activeItem, closePrevious);
newItem = EnsureItem(newItem);
//Problem is here, IsActive is false the first time around in the conductor
if(IsActive)
ScreenExtensions.TryActivate(newItem);
activeItem = newItem;
NotifyOfPropertyChange("ActiveItem");
OnActivationProcessed(activeItem, true);
}
IsActive
プロパティをtrueに設定します。
これを知っているだけで、私はこれを間違って実装していて、導体はルートビューではいけません。私は指揮者(それは少しのように思える)の2番目の子供のビューを持っている必要がありますか?
私はあなたの答えを見つけるまで、これも苦労しました。それは先週だった。今日私は何か他のものを研究していましたが、この動作がhttp://caliburnmicro.com/documentation/composition: の文書に具体的に記載されていることが判明しました>それ自体がアクティブでない導体のアイテムをアクティブにすると、実際には導体が活性化されるまで活性化される。 –