我收到一個奇怪的現象,其中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
公式然而,這似乎頗爲曲折什麼我想實現。
我覺得這種行爲不應該發生但有可能是對此的解釋...