2015-05-22 2 views
0

Я знал, что когда у меня есть вид на вкладке раддокса, событие Loaded запускается каждый раз, когда вид активируется. В моем старом кодексе я устанавливал свойство буфера IsFirstLoad, чтобы избежать этого поведения. С Catel я видел, что, когда ViewModel/View теряет фокус, случается то, что сам viewmodel закрыт ... это нехорошо! Есть ли способ избежать этого?Raddocking with 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 для получения дополнительной информации.

Обратите внимание, что вы несете ответственность за закрытие модели просмотра при использовании этой функции.