2015-10-26 69 views
2

我收到一個奇怪的現象,其中UserControl加載事件觸發時父窗口的內容控件從當前更改爲新的。System.Windows.Controls.UserControl加載的事件觸發'Unloaded'

我已經在多個用戶控件上測試過這種行爲,它發生在所有這些行爲上。

我做了什麼:

窗口:

<xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"/> 

<Controls:TransitioningContentControl Transition="RightReplace" Content="{Binding CurrentViewModel}"/> 

當我改變CurrentViewModel屬性對應的視圖被加載到內容的控制。

用戶控件:

<xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"/> 

<i:Interaction.Triggers> 
    <i:EventTrigger EventName="Loaded"> 
     <i:InvokeCommandAction Command="{Binding Load, Mode=OneWay}"/> 
    </i:EventTrigger> 
</i:Interaction.Triggers> 

UserControl被加載(以及用於當該用戶控件被改變到另一個某些原因)運行Load方法。

可能的解決方案:

有辦法,我想辦法解決這個例如我可以創建一個布爾屬性叫ShouldLoad在Load方法的if公式然而,這似乎頗爲曲折什麼我想實現。

我覺得這種行爲不應該發生但有可能是對此的解釋...

回答

1

我目前在我的應用程序遇到此問題爲好。

到目前爲止,我發現它與<Controls:TransitioningContentControl>有關,它如何使用或放置在何處。我改變了我的用戶界面只使用<ContentControl>和多個加載事件不再發生了我。它似乎也按照預期的那樣工作於<Controls:MetroContentControl>