我知道,当我在raddocking的选项卡中有一个视图时,每次激活该视图时都会触发加载的事件。在我的旧代码中,我设置了一个IsFirstLoad布尔值属性来避免这种行为。在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发布于 2015-05-23 20:16:03
可以使用CloseViewModelOnUnloaded属性控制控件上视图模型的生存期。有关详细信息,请参阅the docs。
请注意,在使用此功能时,您需要负责关闭视图模型。
https://stackoverflow.com/questions/30398999
复制相似问题