Просмотр исходного кода

mvvmlight库使用nuget,去掉了IDataService

tanghai 14 лет назад
Родитель
Сommit
d3498290e1

+ 1 - 1
.gitignore

@@ -15,5 +15,5 @@ Opt/
 bin/
 obj/
 Properties/
-packages/
+Packages/
 

+ 9 - 12
CSharp/Editor/App.xaml

@@ -1,15 +1,12 @@
-<Application x:Class="Egametang.App"
-		xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
-		xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
-		xmlns:vm="clr-namespace:Egametang"
-		xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
-		xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
-		StartupUri="MainWindow.xaml"
-		mc:Ignorable="d">
-
+<?xml version="1.0" encoding="utf-8"?>
+<Application x:Class="Egametang.App" 
+		xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
+		xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
+		xmlns:vm="clr-namespace:Egametang" 
+		xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
+		xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
+		StartupUri="MainWindow.xaml" mc:Ignorable="d">
 	<Application.Resources>
-		<!--Global View Model Locator-->
 		<vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" />
 	</Application.Resources>
-
-</Application>
+</Application>

+ 8 - 10
CSharp/Editor/Editor.csproj

@@ -35,13 +35,13 @@
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
   <ItemGroup>
-    <Reference Include="GalaSoft.MvvmLight.WPF4">
+    <Reference Include="GalaSoft.MvvmLight.Extras.WPF4, Version=3.0.0.32852, Culture=neutral, PublicKeyToken=1673db7d5906b0ad, processorArchitecture=MSIL">
       <SpecificVersion>False</SpecificVersion>
-      <HintPath>C:\Program Files\Laurent Bugnion (GalaSoft)\Mvvm Light Toolkit\Binaries\WPF4\GalaSoft.MvvmLight.WPF4.dll</HintPath>
+      <HintPath>..\packages\MvvmLight.3.0.3\lib\net40\GalaSoft.MvvmLight.Extras.WPF4.dll</HintPath>
     </Reference>
-    <Reference Include="GalaSoft.MvvmLight.Extras.WPF4">
+    <Reference Include="GalaSoft.MvvmLight.WPF4, Version=3.0.0.32852, Culture=neutral, PublicKeyToken=63eb5c012e0b3c1c, processorArchitecture=MSIL">
       <SpecificVersion>False</SpecificVersion>
-      <HintPath>C:\Program Files\Laurent Bugnion (GalaSoft)\Mvvm Light Toolkit\Binaries\WPF4\GalaSoft.MvvmLight.Extras.WPF4.dll</HintPath>
+      <HintPath>..\packages\MvvmLight.3.0.3\lib\net40\GalaSoft.MvvmLight.WPF4.dll</HintPath>
     </Reference>
     <Reference Include="Microsoft.Practices.ServiceLocation">
       <SpecificVersion>False</SpecificVersion>
@@ -53,12 +53,11 @@
     <Reference Include="NLog.Extended">
       <HintPath>..\packages\NLog.2.0.0.0\lib\NET40\NLog.Extended.dll</HintPath>
     </Reference>
-    <Reference Include="System.Windows.Interactivity">
-      <SpecificVersion>False</SpecificVersion>
-      <HintPath>C:\Program Files\Laurent Bugnion (GalaSoft)\Mvvm Light Toolkit\Binaries\WPF4\System.Windows.Interactivity.dll</HintPath>
-    </Reference>
     <Reference Include="System" />
     <Reference Include="System.Data" />
+    <Reference Include="System.Windows.Interactivity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+      <HintPath>..\packages\MvvmLight.3.0.3\lib\net40\System.Windows.Interactivity.dll</HintPath>
+    </Reference>
     <Reference Include="System.Xml" />
     <Reference Include="Microsoft.CSharp" />
     <Reference Include="System.Core" />
@@ -76,12 +75,11 @@
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
     </ApplicationDefinition>
-    <Compile Include="Model\DataService.cs" />
-    <Compile Include="Model\IDataService.cs" />
     <None Include="NLog.config">
       <SubType>Designer</SubType>
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     </None>
+    <Compile Include="Model\Main.cs" />
     <Compile Include="ViewModel\MainViewModel.cs" />
     <Compile Include="ViewModel\ViewModelLocator.cs" />
     <Compile Include="View\MainView.xaml.cs">

+ 1 - 2
CSharp/Editor/MainWindow.xaml

@@ -4,8 +4,7 @@
 		xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 		xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 		xmlns:v="clr-namespace:Egametang"
-		mc:Ignorable="d" Height="600" Width="800" Title="MVVM Light Application"
-		DataContext="{Binding Main, Source={StaticResource Locator}}">
+		mc:Ignorable="d" Height="600" Width="800" Title="MVVM Light Application">
 	<Grid x:Name="LayoutRoot">
 		<TabControl HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
 			<TabItem Header="Main" Name="mainTabItem">

+ 0 - 8
CSharp/Editor/Model/DataService.cs

@@ -1,8 +0,0 @@
-using System;
-
-namespace Egametang
-{
-	public class DataService : IDataService
-	{
-	}
-}

+ 0 - 11
CSharp/Editor/Model/IDataService.cs

@@ -1,11 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace Egametang
-{
-	public interface IDataService
-	{
-	}
-}

+ 20 - 0
CSharp/Editor/Model/Main.cs

@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Egametang
+{
+	public class Main
+	{
+		public Main()
+		{
+			LoginResult = "";
+		}
+		public string LoginResult
+		{
+			get;
+			set;
+		}
+	}
+}

+ 1 - 0
CSharp/Editor/Packages.config

@@ -1,4 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
 <packages>
+	<package id="MvvmLight" version="3.0.3" />
 	<package id="NLog" version="2.0.0.0" />
 </packages>

+ 1 - 1
CSharp/Editor/View/MainView.xaml

@@ -4,7 +4,7 @@
 		xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
 		xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
 		mc:Ignorable="d" d:DesignHeight="600" d:DesignWidth="800"
-		DataContext="{Binding Main, Source={StaticResource Locator}}" >
+		DataContext="{Binding MainViewModel, Source={StaticResource Locator}}" >
 	<StackPanel>
 		<Label HorizontalAlignment="Center" VerticalAlignment="Center" Content="{Binding LoginResult}" />
 		<Button Content="登录" HorizontalAlignment="Center" VerticalAlignment="Center" Command="{Binding LoginCmd}" />

+ 11 - 11
CSharp/Editor/ViewModel/MainViewModel.cs

@@ -4,42 +4,42 @@ using System.Windows.Threading;
 using GalaSoft.MvvmLight;
 using GalaSoft.MvvmLight.Command;
 using GalaSoft.MvvmLight.Threading;
-using System.Threading;
 
 namespace Egametang
 {
 	public class MainViewModel : ViewModelBase
 	{
-		private readonly IDataService dataService;
-		private string loginResult = "";
+		private Main main = new Main();
+		private RelayCommand loginCmd = null;
 
-		public MainViewModel(IDataService dataService)
+		public MainViewModel()
 		{
-			this.dataService = dataService;
-			LoginCmd = new RelayCommand(AsyncLogin);
+			loginCmd = new RelayCommand(AsyncLogin);
 		}
 
 		public string LoginResult
 		{
 			get
 			{
-				return loginResult;
+				return main.LoginResult;
 			}
 			set
 			{
-				if (loginResult == value)
+				if (main.LoginResult == value)
 				{
 					return;
 				}
-				loginResult = value;
+				main.LoginResult = value;
 				RaisePropertyChanged("LoginResult");
 			}
 		}
 
 		public RelayCommand LoginCmd
 		{
-			get;
-			private set;
+			get
+			{
+				return loginCmd;
+			}
 		}
 
 		private void AsyncLogin()

+ 4 - 17
CSharp/Editor/ViewModel/ViewModelLocator.cs

@@ -1,28 +1,15 @@
-using GalaSoft.MvvmLight;
-using GalaSoft.MvvmLight.Ioc;
-using Microsoft.Practices.ServiceLocation;
-
+
 namespace Egametang
 {
 	public class ViewModelLocator
 	{
-		static ViewModelLocator()
-		{
-			ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
-
-			SimpleIoc.Default.Register<IDataService, DataService>();
-
-			SimpleIoc.Default.Register<MainViewModel>();
-		}
+		static private MainViewModel mainViewModel = new MainViewModel();
 
-		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
-			"CA1822:MarkMembersAsStatic",
-			Justification = "This non-static member is needed for data binding purposes.")]
-		public MainViewModel Main
+		public static MainViewModel MainViewModel
 		{
 			get
 			{
-				return ServiceLocator.Current.GetInstance<MainViewModel>();
+				return mainViewModel;
 			}
 		}