using Microsoft.Practices.Composite.Regions;
using Microsoft.Practices.ServiceLocation;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Telerik.Windows.Controls;

namespace ModuleB
{
	public partial class Pane4 
	{
		public Pane4()
		{
			InitializeComponent();
            Thread.SpinWait(100000000);
            this.Loaded += Pane4_Loaded;
		}

        private void Pane4_Loaded(object sender, RoutedEventArgs e)
        {
            this.Loaded -= Pane4_Loaded;
            if (this.DataContext != null)
            {
                ((ViewTesterVm)DataContext).ActiveView = this;
            }
        }

        private void Activate(object sender, RoutedEventArgs e)
        {
            var regionManager = ServiceLocator.Current.GetInstance<IRegionManager>();
            foreach(var view in regionManager.Regions["MainRegion"].Views)
            {
                if (view.GetType().Name.Contains("Panel3Vm"))
                {
                    regionManager.Regions["MainRegion"].Activate(view);
                    
                    return;
                }
            }
            regionManager.RegisterViewWithRegion("MainRegion", typeof(Panel3Vm));
        }
    }
}
