使用Catel进行Raddocking以及如何避免重新调用初始化方法

时间:2015-05-22 14:12:23

标签: mvvm telerik catel

我知道当我在raddocking选项卡中查看视图时,每次激活视图时都会触发Loaded事件。在我的旧代码中,我设置了一个IsFirstLoad布尔属性来避免这种行为。使用Catel我已经看到,当ViewModel / View失去焦点时,它会发生在视图模型本身关闭的地方......这不是好事!有没有办法可以避免这种情况?

由于

   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

1 个答案:

答案 0 :(得分:0)

您可以使用CloseViewModelOnUnloaded属性控制控件上视图模型的生命周期。有关详细信息,请参阅the docs

请注意,您在使用此功能时负责关闭视图模型。