2015-05-22 39 views
0

我知道,當我在raddocking的選項卡中查看視圖時,每次激活視圖時都會觸發Loaded事件。在我的舊代碼中,我設置了一個IsFirstLoad布爾屬性來避免這種行爲。與Catel我已經看到,當ViewModel/View失去焦點時,它發生了什麼視圖模型本身被關閉......這是不好的!有沒有辦法可以避免這種情況?Raddocking與Catel以及如何避免初始化方法被召回

感謝

04:04:18:328 => [DEBUG] [Catel.MVVM.ViewModelManager] [1] Unregistering all models of view model 'ServerMonitorViewModel' (id = '6') 
04:04:18:329 => [DEBUG] [Catel.MVVM.ViewModelManager] [1] Unregistered all '0' models of view model 'ServerMonitorViewModel' (id = '6') 
04:04:18:329 => [DEBUG] [Catel.MVVM.ViewModelCommandManager] [1] Unregistering commands on view model 'myApp..ServerMonitorViewModel' with unique identifier '6' 
04:04:18:330 => [DEBUG] [Catel.MVVM.ViewModelCommandManager] [1] Unregistered commands on view model 'myApp..ServerMonitorViewModel' with unique identifier '6' 
myApp.exe Information: 0 :  04:04:18:330 => [INFO] [Catel.MVVM.ViewModelBase] [1] Closed view model 'myApp..ServerMonitorViewModel' 
04:04:18:331 => [DEBUG] [Catel.MVVM.ManagedViewModel] [1] Removed view model instance, currently containing '0' instances of type 'myApp..ServerMonitorViewModel' 
04:04:18:335 => [DEBUG] [Catel.MVVM.Views.ViewToViewModelMappingHelper] [1] Initializing view model 'null' 
04:04:18:335 => [DEBUG] [Catel.MVVM.Views.ViewToViewModelMappingHelper] [1] Uninitializing view model 'ServerMonitorViewModel' 
04:04:18:335 => [DEBUG] [Catel.MVVM.Views.ViewToViewModelMappingHelper] [1] Uninitialized view model 'ServerMonitorViewModel' 
04:04:18:336 => [DEBUG] [Catel.MVVM.Views.ViewToViewModelMappingHelper] [1] Initialized view model 'null' 
04:04:18:355 => [DEBUG] [Catel.MVVM.Views.ViewToViewModelMappingHelper] [1] Uninitializing view model container to manage ViewToViewModel mappings 
04:04:18:357 => [DEBUG] [Catel.MVVM.Views.ViewToViewModelMappingHelper] [1] Uninitialized view model container to manage ViewToViewModel mappings 
04:04:25:346 => [DEBUG] [Catel.MVVM.Providers.LogicBase] [1] Target view 'ServerMonitorView' is loaded 
04:04:25:348 => [DEBUG] [Catel.MVVM.Views.ViewManager] [1] Registering view 'IF.Tesoreria.Client.WPF.Views.ServerMonitorView' 
04:04:25:349 => [DEBUG] [Catel.MVVM.Views.ViewManager] [1] Registered view 'IF.Tesoreria.Client.WPF.Views.ServerMonitorView' 
04:04:25:352 => [DEBUG] [Catel.MVVM.Providers.UserControlLogic] [1] Searching for an instance of the InfoBarMessageControl 
04:04:25:353 => [DEBUG] [Catel.MVVM.Providers.UserControlLogic] [1] Finished searching for an instance of the InfoBarMessageControl 
04:04:25:354 => [DEBUG] [Catel.MVVM.Providers.UserControlLogic] [1] Found the parent view model container 'DockingPanesView' for 'ServerMonitorView' 
04:04:25:354 => [DEBUG] [Catel.MVVM.Providers.UserControlLogic] [1] Subscribed to parent view model 'myApp..DockingPanesViewModel' 
myApp.exe Information: 0 :  04:04:25:355 => [INFO] [Catel.MVVM.Providers.LogicBase] [1] DataContext of type 'myApp..ServerMonitorViewModel' is allowed to be reused by view 'IF.Tesoreria.Client.WPF.Views.ServerMonitorView', using the current DataContext as view model 
04:04:25:375 => [DEBUG] [Catel.MVVM.Views.ViewToViewModelMappingHelper] [1] Initializing view model container to manage ViewToViewModel mappings 
04:04:25:377 => [DEBUG] [Catel.MVVM.Views.ViewToViewModelMappingHelper] [1] Initializing view model 'ServerMonitorViewModel' 
04:04:25:377 => [DEBUG] [Catel.MVVM.Views.ViewToViewModelMappingHelper] [1] Initialized view model 'ServerMonitorViewModel' 
04:04:25:378 => [DEBUG] [Catel.MVVM.Views.ViewToViewModelMappingHelper] [1] Initialized view model container to manage ViewToViewModel mappings 
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='Telerik.Windows.Controls.RadListBox', AncestorLevel='1''. BindingExpression:Path=DataContext.Reconnect; DataItem=null; target element is 'EventToCommand' (HashCode=64707792); target property is 'Command' (type 'ICommand') 
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='Telerik.Windows.Controls.RadListBox', AncestorLevel='1''. BindingExpression:Path=DataContext.Reconnect; DataItem=null; target element is 'EventToCommand' (HashCode=45499220); target property is 'Command' (type 'ICommand') 
The thread 0x6a08 has exited with code 259 (0x103). 
04:04:29:773 => [DEBUG] [Catel.MVVM.Providers.LogicBase] [1] Target control 'ServerMonitorView' is unloaded 
04:04:29:775 => [DEBUG] [Catel.MVVM.Views.ViewManager] [1] Unregistering view 'IF.Tesoreria.Client.WPF.Views.ServerMonitorView' 
04:04:29:776 => [DEBUG] [Catel.MVVM.Views.ViewManager] [1] Unregistered view 'IF.Tesoreria.Client.WPF.Views.ServerMonitorView' 
04:04:29:777 => [DEBUG] [Catel.MVVM.Providers.UserControlLogic] [1] Cleared all warnings and errors caused by 'myApp..ServerMonitorViewModel (ID = 6)' since this is caused by a DataContext issue in the .NET Framework 
04:04:29:779 => [DEBUG] [Catel.MVVM.Providers.UserControlLogic] [1] Unsubscribed from parent view model 
04:04:29:785 => [DEBUG] [Catel.MVVM.Views.ViewToViewModelMappingHelper] [1] Initializing view model 'null' 
04:04:29:786 => [DEBUG] [Catel.MVVM.Views.ViewToViewModelMappingHelper] [1] Uninitializing view model 'ServerMonitorViewModel' 
04:04:29:788 => [DEBUG] [Catel.MVVM.Views.ViewToViewModelMappingHelper] [1] Uninitialized view model 'ServerMonitorViewModel' 
04:04:29:788 => [DEBUG] [Catel.MVVM.Views.ViewToViewModelMappingHelper] [1] Initialized view model 'null' 
04:04:29:792 => [DEBUG] [Catel.MVVM.Views.ViewToViewModelMappingHelper] [1] Uninitializing view model container to manage ViewToViewModel mappings 
04:04:29:793 => [DEBUG] [Catel.MVVM.Views.ViewToViewModelMappingHelper] [1] Uninitialized view model container to manage ViewToViewModel mappings 

回答

0

您可以控制視圖模型的生命週期上使用CloseViewModelOnUnloaded屬性的控件。有關更多信息,請參閱the docs

請注意,您在使用此功能時負責關閉視圖模型。

相關問題