WindowManager and Singleton Windows

Topics: Framework Services, UI Architecture
Jun 15, 2012 at 7:50 PM

I have a window in my application which is configured as a singleton

this.windsorContainer.Register(Component.For<ILogViewModel>().ImplementedBy<LogViewModel>().LifeStyle.Is(LifestyleType.Singleton));

Now, If I have a functon

public void OpenLogWindow() {  
    this.WindowManagerExtended.ShowSingletonWindow(IoC.Get<ILogViewModel>());
}

and when a user calls this function multiple times, you get multiple views opening. (All bound to the same view model)

I only want one window to appear. Subsequent calls to this function should act as a BringToFront.

I'm just wondering how other people have dealt with this situation?

 

I was thinking something along the lines of:

public class WindowManagerExtended : WindowManager, IWindowManagerExtended
    {
        private readonly List<object> openWindows = new List<object>();

        public void ShowSingletonWindow(object rootModel, object context = null, IDictionary<string, object> settings = null)
        {
            ViewModelBase viewModel = rootModel as ViewModelBase;

            if (openWindows.Contains(rootModel))
            {
                // TODO figure out a way to bring this view to front?
                return;
            }
          
            this.openWindows.Add(rootModel);

            if (viewModel != null)
            {
                viewModel.Deactivated += this.ViewModelDeactivated;
            }

            this.ShowWindow(rootModel, context, settings);
        }

        private void ViewModelDeactivated(object sender, DeactivationEventArgs e)
        {
            this.openWindows.Remove(sender);
        }
    }

I'm currently unsure how I will get that window to "bring to front" but I figure it should be doable.

 

Any thoughts?

 

Thanks

Scott

 

Jun 15, 2012 at 7:51 PM

I forgot to mention that I was also looking at using a Conductor, but it appears that this is more designed for ContentControls rather than popup windows.