Commits

Anonymous committed 436963a

Проба с контроллером и region manager

Comments (0)

Files changed (18)

TFS_Tasker/Controller/WindowSwitchController.cs

+using System.ComponentModel.Composition;
+using Microsoft.Practices.Prism.Events;
+using Microsoft.Practices.Prism.Regions;
+using Tasker.Event;
+using Tasker.Infrastructure;
+using Tasker.View;
+
+namespace Tasker.Controller
+{
+	public class WindowSwitchController
+	{
+		private readonly IEventAggregator _eventAggregator;
+		private readonly IRegionManager _regionManager;
+
+		public WindowSwitchController(IRegionManager regionManager, IEventAggregator eventAggregator)
+		{
+			this._eventAggregator = eventAggregator;
+			this._regionManager = regionManager;
+
+			this._eventAggregator.GetEvent<AboutViewSelectEvent>()
+				.Subscribe(ShowAboutView, ThreadOption.UIThread, true);
+		}
+
+		private void ShowAboutView(object _)
+		{
+			var mainRegion = this._regionManager.Regions[RegionNames.MainRegion];
+			var aboutView = mainRegion.GetView(typeof(AboutView).ToString());
+			if (aboutView == null)
+			{
+				aboutView = new AboutView();
+				mainRegion.Add(aboutView, typeof(AboutView).ToString());
+			}
+			mainRegion.Activate(aboutView);
+		}
+	}
+}

TFS_Tasker/Controller/WorkItemListController.cs

 	[Export]
 	public class WorkItemListController
 	{
-		private IEventAggregator _eventAggregator;
+		private readonly IEventAggregator _eventAggregator;
 
 		[ImportingConstructor]
 		public WorkItemListController(IEventAggregator eventAggregator)

TFS_Tasker/Event/AboutViewSelectEvent.cs

+using Microsoft.Practices.Prism.Events;
+
+namespace Tasker.Event
+{
+	public class AboutViewSelectEvent : CompositePresentationEvent<object>
+	{
+	}
+}

TFS_Tasker/Tasker.csproj

       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
     </ApplicationDefinition>
+    <Compile Include="Controller\ShellController.cs" />
     <Compile Include="Controller\WorkItemListController.cs" />
+    <Compile Include="Event\AboutViewSelectEvent.cs" />
     <Compile Include="Event\ChangeQueryEvent.cs" />
     <Compile Include="Infrastructure\Bootstrapper.cs" />
     <Compile Include="Infrastructure\ILog.cs" />
     <Compile Include="ViewModel\QueryListViewModel.cs" />
     <Compile Include="ViewModel\ShellViewModel.cs" />
     <Compile Include="ViewModel\ViewModelBase.cs" />
+    <Compile Include="ViewModel\WindowSwitchViewModel.cs" />
     <Compile Include="ViewModel\WorkItemListViewModel.cs" />
     <Compile Include="ViewModel\WorkItemViewModel.cs" />
     <Compile Include="View\AboutView.xaml.cs">

TFS_Tasker/TaskerModule.cs

 using System.ComponentModel.Composition;
+using Microsoft.Practices.Prism.Events;
 using Microsoft.Practices.Prism.MefExtensions.Modularity;
 using Microsoft.Practices.Prism.Modularity;
 using Microsoft.Practices.Prism.Regions;
+using Tasker.Controller;
 using Tasker.Infrastructure;
 using Tasker.View;
+using Tasker.ViewModel;
 
 namespace Tasker
 {
 	public class TaskerModule : IModule
 	{
 		private readonly IRegionManager _regionManager;
+		private readonly IEventAggregator _eventAggregator;
 
 		[ImportingConstructor]
-		public TaskerModule(IRegionManager regionManager)
+		public TaskerModule(IRegionManager regionManager, IEventAggregator eventAggregetor)
 		{
 			this._regionManager = regionManager;
+			this._eventAggregator = eventAggregetor;
 		}
 
 		public void Initialize()
 		{
-			this._regionManager.RegisterViewWithRegion(RegionNames.NavigationRegion, typeof(WindowSwitchView));
+			var view = new WindowSwitchView();
+			var model = new WindowSwitchViewModel(this._eventAggregator);
+			view.DataContext = model;
+			this._regionManager.RegisterViewWithRegion(RegionNames.NavigationRegion, () => view);
+			new WindowSwitchController(this._regionManager, this._eventAggregator);
 		}
 	}
 }

TFS_Tasker/View/AboutView.xaml

              mc:Ignorable="d" 
              d:DesignHeight="300" d:DesignWidth="300">
     <Grid>
-            
+        <TextBlock>ABOUT View</TextBlock>
     </Grid>
 </UserControl>

TFS_Tasker/View/SettingsView.xaml

              mc:Ignorable="d" 
              d:DesignHeight="300" d:DesignWidth="300">
     <Grid>
-            
+        <TextBlock>Settings</TextBlock>
     </Grid>
 </UserControl>

TFS_Tasker/View/WindowSwitchView.xaml

              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
-             mc:Ignorable="d" 
-             d:DesignHeight="300" d:DesignWidth="300">
+             mc:Ignorable="d">
     <StackPanel Orientation="Horizontal">
         <RadioButton Content="Work Items" Style="{StaticResource {x:Type ToggleButton}}" />
         <RadioButton Content="Configure" Style="{StaticResource {x:Type ToggleButton}}" />
-        <RadioButton Content="About" Style="{StaticResource {x:Type ToggleButton}}" />
+        <RadioButton Content="About" Style="{StaticResource {x:Type ToggleButton}}" Command="{Binding Path=ShowAboutViewCommand}" />
     </StackPanel>
     <!--<ListBox>
         <ListBox.ItemTemplate>

TFS_Tasker/View/WindowSwitchView.xaml.cs

 		{
 			InitializeComponent();
 		}
+
+		private void RadioButton_Click(object sender, System.Windows.RoutedEventArgs e)
+		{
+
+		}
 	}
 }

TFS_Tasker/ViewModel/WindowSwitchViewModel.cs

+using Microsoft.Practices.Prism.Commands;
+using Microsoft.Practices.Prism.Events;
+using Tasker.Event;
+
+namespace Tasker.ViewModel
+{
+	public class WindowSwitchViewModel : ViewModelBase
+	{
+		private readonly IEventAggregator _eventAggregator;
+
+		public WindowSwitchViewModel(IEventAggregator eventAggregator)
+		{
+			this._eventAggregator = eventAggregator;
+			this.ShowAboutViewCommand = new DelegateCommand<object>(this.ShowAboutView, this.CanShowAboutView);
+		}
+
+		public DelegateCommand<object> ShowAboutViewCommand { get; private set; }
+
+		private void ShowAboutView(object commandArg)
+		{
+			this._eventAggregator.GetEvent<AboutViewSelectEvent>().Publish(new object());
+		}
+
+		private bool CanShowAboutView(object commandArg)
+		{
+			return true;
+		}
+	}
+}

Tasker.TFS.Tests/Microsoft.TeamFoundation.Client.moles

+<Moles xmlns="http://schemas.microsoft.com/moles/2010/">
+  <Assembly Name="Microsoft.TeamFoundation.Client" />
+</Moles>