大佬教程收集整理的这篇文章主要介绍了wpf – 使用WindowManager重新激活退出窗口,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
private void OpenOrReactivateInfoView() { if(this.infoviewmodel == null) { this.infoviewmodel = new Infoviewmodel(); } this.windowManager.ShowWindow(this.infoviewmodel); }
每次调用OpenOrReactivateInfoView()时,我都不想打开一个新窗口,而是想检查窗口是否仍然打开,如果是,则现有窗口应该重新获得焦点.
我们将成为一名优秀的Calibrun.Micro方式来解决这个问题?我确实希望避免在viewmodel中保留对窗口(或任何UIElement)的引用.另请注意,这是许多无模式对话框的常见行为,因此最好以通用的可重用方式解决此问题.
Caliburn.Micro是否已经拥有内置的手段?
假设你没有,那么像下面这样简单的东西应该可以做到
实际上计划打开足够的窗户甚至死亡的WeakReferences
会影响表现.如果它将长期运行它不应该
很难实现某种清理.
public class MyFancyWindowManager : WindowManager { IDictionary<WeakReference,WeakReference> windows = new Dictionary<WeakReference,WeakReference>(); public override void ShowWindow(object rootModel,object context = null,IDictionary<String,object> setTings = null) { NavigationWindow navWindow = null; if (Application.Current != null && Application.Current.MainWindow != null) { navWindow = Application.Current.MainWindow as NavigationWindow; } if (navWindow != null) { var window = CreatePage(rootModel,context,setTings); navWindow.Navigate(window); } else { var window = GetExisTingWindow(rootModel); if (window == null) { window = CreateWindow(rootModel,false,setTings); windows.Add(new WeakReference(rootModel),new WeakReference(window)); window.Show(); } else { window.Focus(); } } } protected virtual Window GetExisTingWindow(object model) { if(!windows.Any(d => d.Key.IsAlive && d.Key.Target == model)) return null; var exisTingWindow = windows.Single(d => d.Key.Target == model).Value; return exisTingWindow.IsAlive ? exisTingWindow.Target as Window : null; } }
以上是大佬教程为你收集整理的wpf – 使用WindowManager重新激活退出窗口全部内容,希望文章能够帮你解决wpf – 使用WindowManager重新激活退出窗口所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。