Преглед изворни кода

基于Prism框架运行成功!

tanghai пре 14 година
родитељ
комит
302d6fd677

+ 1 - 0
CSharp/Editor/Bootstrapper.cs

@@ -12,6 +12,7 @@ namespace Editor
 		protected override void ConfigureAggregateCatalog()
 		{
 			this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(Bootstrapper).Assembly));
+			this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(ViewExportAttribute).Assembly));
 			this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(LoginModule).Assembly));
 		}
 

+ 0 - 106
CSharp/Infrastructure/DialogActivationBehavior.cs

@@ -1,106 +0,0 @@
-//===================================================================================
-// Microsoft patterns & practices
-// Composite Application Guidance for Windows Presentation Foundation and Silverlight
-//===================================================================================
-// Copyright (c) Microsoft Corporation.  All rights reserved.
-// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
-// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
-// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
-// FITNESS FOR A PARTICULAR PURPOSE.
-//===================================================================================
-// The example companies, organizations, products, domain names,
-// e-mail addresses, logos, people, places, and events depicted
-// herein are fictitious.  No association with any real company,
-// organization, product, domain name, email address, logo, person,
-// places, or events is intended or should be inferred.
-//===================================================================================
-using System.Collections.Specialized;
-using System.Windows;
-using Microsoft.Practices.Prism.Regions;
-using Microsoft.Practices.Prism.Regions.Behaviors;
-
-namespace Infrastructure
-{
-    /// <summary>
-    /// Defines a behavior that creates a Dialog to display the active view of the target <see cref="IRegion"/>.
-    /// </summary>
-    public abstract class DialogActivationBehavior : RegionBehavior, IHostAwareRegionBehavior
-    {
-        /// <summary>
-        /// The key of this behavior
-        /// </summary>
-        public const string BehaviorKey = "DialogActivation";
-
-        private IWindow contentDialog;
-
-        /// <summary>
-        /// Gets or sets the <see cref="DependencyObject"/> that the <see cref="IRegion"/> is attached to.
-        /// </summary>
-        /// <value>A <see cref="DependencyObject"/> that the <see cref="IRegion"/> is attached to.
-        /// This is usually a <see cref="FrameworkElement"/> that is part of the tree.</value>
-        public DependencyObject HostControl { get; set; }
-
-        /// <summary>
-        /// Performs the logic after the behavior has been attached.
-        /// </summary>
-        protected override void OnAttach()
-        {
-            this.Region.ActiveViews.CollectionChanged += this.ActiveViews_CollectionChanged;
-        }
-
-        /// <summary>
-        /// Override this method to create an instance of the <see cref="IWindow"/> that 
-        /// will be shown when a view is activated.
-        /// </summary>
-        /// <returns>
-        /// An instance of <see cref="IWindow"/> that will be shown when a 
-        /// view is activated on the target <see cref="IRegion"/>.
-        /// </returns>
-        protected abstract IWindow CreateWindow();
-
-        private void ActiveViews_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
-        {
-            if (e.Action == NotifyCollectionChangedAction.Add)
-            {
-                this.CloseContentDialog();
-                this.PrepareContentDialog(e.NewItems[0]);
-            }
-            else if (e.Action == NotifyCollectionChangedAction.Remove)
-            {
-                this.CloseContentDialog();
-            }
-        }
-
-        private Style GetStyleForView()
-        {
-            return this.HostControl.GetValue(RegionPopupBehaviors.ContainerWindowStyleProperty) as Style;
-        }
-
-        private void PrepareContentDialog(object view)
-        {
-            this.contentDialog = this.CreateWindow();
-            this.contentDialog.Content = view;
-            this.contentDialog.Owner = this.HostControl;
-            this.contentDialog.Closed += this.ContentDialogClosed;
-            this.contentDialog.Style = this.GetStyleForView();
-            this.contentDialog.Show();
-        }
-
-        private void CloseContentDialog()
-        {
-            if (this.contentDialog != null)
-            {
-                this.contentDialog.Closed -= this.ContentDialogClosed;
-                this.contentDialog.Close();
-                this.contentDialog.Content = null;
-                this.contentDialog.Owner = null;
-            }
-        }
-
-        private void ContentDialogClosed(object sender, System.EventArgs e)
-        {
-            this.Region.Deactivate(this.contentDialog.Content);
-            this.CloseContentDialog();
-        }
-    }
-}

+ 7 - 4
CSharp/Infrastructure/IViewRegionRegistration.cs

@@ -17,8 +17,11 @@
 
 namespace Infrastructure
 {
-    public interface IViewRegionRegistration
-    {
-        string RegionName { get; }
-    }
+	public interface IViewRegionRegistration
+	{
+		string RegionName 
+		{ 
+			get;
+		}
+	}
 }

+ 0 - 57
CSharp/Infrastructure/IWindow.cs

@@ -1,57 +0,0 @@
-//===================================================================================
-// Microsoft patterns & practices
-// Composite Application Guidance for Windows Presentation Foundation and Silverlight
-//===================================================================================
-// Copyright (c) Microsoft Corporation.  All rights reserved.
-// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
-// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
-// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
-// FITNESS FOR A PARTICULAR PURPOSE.
-//===================================================================================
-// The example companies, organizations, products, domain names,
-// e-mail addresses, logos, people, places, and events depicted
-// herein are fictitious.  No association with any real company,
-// organization, product, domain name, email address, logo, person,
-// places, or events is intended or should be inferred.
-//===================================================================================
-using System;
-using System.Windows;
-
-namespace Infrastructure
-{
-    /// <summary>
-    /// Defines the interface for the Dialogs that are shown by <see cref="DialogActivationBehavior"/>.
-    /// </summary>
-    public interface IWindow
-    {
-        /// <summary>
-        /// Ocurrs when the <see cref="IWindow"/> is closed.
-        /// </summary>
-        event EventHandler Closed;
-
-        /// <summary>
-        /// Gets or sets the content for the <see cref="IWindow"/>.
-        /// </summary>
-        object Content { get; set; }
-
-        /// <summary>
-        /// Gets or sets the owner control of the <see cref="IWindow"/>.
-        /// </summary>
-        object Owner { get; set; }
-
-        /// <summary>
-        /// Gets or sets the <see cref="System.Windows.Style"/> to apply to the <see cref="IWindow"/>.
-        /// </summary>
-        Style Style { get; set; }
-
-        /// <summary>
-        /// Opens the <see cref="IWindow"/>.
-        /// </summary>
-        void Show();
-
-        /// <summary>
-        /// Closes the <see cref="IWindow"/>.
-        /// </summary>
-        void Close();
-    }
-}

+ 0 - 6
CSharp/Infrastructure/Infrastructure.csproj

@@ -47,14 +47,8 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="AutoPopulateExportedViewsBehavior.cs" />
-    <Compile Include="DialogActivationBehavior.cs" />
     <Compile Include="IViewRegionRegistration.cs" />
-    <Compile Include="IWindow.cs" />
-    <Compile Include="RegionPopupBehaviors.cs" />
-    <Compile Include="ReturnCommandBehavior.cs" />
     <Compile Include="ViewExportAttribute.cs" />
-    <Compile Include="WindowDialogActivationBehavior.Desktop.cs" />
-    <Compile Include="WindowWrapper.Desktop.cs" />
   </ItemGroup>
   <ItemGroup>
     <Folder Include="Properties\" />

+ 0 - 138
CSharp/Infrastructure/RegionPopupBehaviors.cs

@@ -1,138 +0,0 @@
-//===================================================================================
-// Microsoft patterns & practices
-// Composite Application Guidance for Windows Presentation Foundation and Silverlight
-//===================================================================================
-// Copyright (c) Microsoft Corporation.  All rights reserved.
-// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
-// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
-// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
-// FITNESS FOR A PARTICULAR PURPOSE.
-//===================================================================================
-// The example companies, organizations, products, domain names,
-// e-mail addresses, logos, people, places, and events depicted
-// herein are fictitious.  No association with any real company,
-// organization, product, domain name, email address, logo, person,
-// places, or events is intended or should be inferred.
-//===================================================================================
-using System.ComponentModel;
-using System.Windows;
-using Microsoft.Practices.Prism.Regions;
-using Microsoft.Practices.ServiceLocation;
-
-namespace Infrastructure
-{
-    /// <summary>
-    /// Declares the Attached Properties and Behaviors for implementing Popup regions.
-    /// </summary>
-    /// <remarks>
-    /// Although the fastest way is to create a RegionAdapter for a Window and register it with the RegionAdapterMappings,
-    /// this would be conceptually incorrect because we want to create a new popup window everytime a view is added 
-    /// (instead of having a Window as a host control and replacing its contents everytime Views are added, as other adapters do).
-    /// This is why we have a different class for this behavior, instead of reusing the <see cref="RegionManager.RegionNameProperty"/> attached property.
-    /// </remarks>
-    public static class RegionPopupBehaviors
-    {
-        /// <summary>
-        /// The name of the Popup <see cref="IRegion"/>.
-        /// </summary>
-        public static readonly DependencyProperty CreatePopupRegionWithNameProperty =
-            DependencyProperty.RegisterAttached("CreatePopupRegionWithName", typeof(string), typeof(RegionPopupBehaviors), new PropertyMetadata(CreatePopupRegionWithNamePropertyChanged));
-
-        /// <summary>
-        /// The <see cref="Style"/> to set to the Popup.
-        /// </summary>
-        public static readonly DependencyProperty ContainerWindowStyleProperty =
-          DependencyProperty.RegisterAttached("ContainerWindowStyle", typeof(Style), typeof(RegionPopupBehaviors), null);
-
-        /// <summary>
-        /// Gets the name of the Popup <see cref="IRegion"/>.
-        /// </summary>
-        /// <param name="owner">Owner of the Popup.</param>
-        /// <returns>The name of the Popup <see cref="IRegion"/>.</returns>
-        public static string GetCreatePopupRegionWithName(DependencyObject owner)
-        {
-            return owner.GetValue(CreatePopupRegionWithNameProperty) as string;
-        }
-
-        /// <summary>
-        /// Sets the name of the Popup <see cref="IRegion"/>.
-        /// </summary>
-        /// <param name="owner">Owner of the Popup.</param>
-        /// <param name="value">Name of the Popup <see cref="IRegion"/>.</param>
-        public static void SetCreatePopupRegionWithName(DependencyObject owner, string value)
-        {
-            owner.SetValue(CreatePopupRegionWithNameProperty, value);
-        }
-
-        /// <summary>
-        /// Gets the <see cref="Style"/> for the Popup.
-        /// </summary>
-        /// <param name="owner">Owner of the Popup.</param>
-        /// <returns>The <see cref="Style"/> for the Popup.</returns>
-        public static Style GetContainerWindowStyle(DependencyObject owner)
-        {
-            return owner.GetValue(ContainerWindowStyleProperty) as Style;
-        }
-
-        /// <summary>
-        /// Sets the <see cref="Style"/> for the Popup.
-        /// </summary>
-        /// <param name="owner">Owner of the Popup.</param>
-        /// <param name="style"><see cref="Style"/> for the Popup.</param>
-        public static void SetContainerWindowStyle(DependencyObject owner, Style style)
-        {
-            owner.SetValue(ContainerWindowStyleProperty, style);
-        }
-
-        /// <summary>
-        /// Creates a new <see cref="IRegion"/> and registers it in the default <see cref="IRegionManager"/>
-        /// attaching to it a <see cref="DialogActivationBehavior"/> behavior.
-        /// </summary>
-        /// <param name="owner">The owner of the Popup.</param>
-        /// <param name="regionName">The name of the <see cref="IRegion"/>.</param>
-        /// <remarks>
-        /// This method would typically not be called directly, instead the behavior 
-        /// should be set through the Attached Property <see cref="CreatePopupRegionWithNameProperty"/>.
-        /// </remarks>
-        public static void RegisterNewPopupRegion(DependencyObject owner, string regionName)
-        {
-            // Creates a new region and registers it in the default region manager.
-            // Another option if you need the complete infrastructure with the default region behaviors
-            // is to extend DelayedRegionCreationBehavior overriding the CreateRegion method and create an 
-            // instance of it that will be in charge of registering the Region once a RegionManager is
-            // set as an attached property in the Visual Tree.
-            IRegionManager regionManager = ServiceLocator.Current.GetInstance<IRegionManager>();
-            if (regionManager != null)
-            {
-                IRegion region = new SingleActiveRegion();
-                DialogActivationBehavior behavior;
-#if SILVERLIGHT
-                behavior = new PopupDialogActivationBehavior();
-#else
-                behavior = new WindowDialogActivationBehavior();
-#endif
-                behavior.HostControl = owner;
-
-                region.Behaviors.Add(DialogActivationBehavior.BehaviorKey, behavior);
-                regionManager.Regions.Add(regionName, region);
-            }
-        }
-
-        private static void CreatePopupRegionWithNamePropertyChanged(DependencyObject hostControl, DependencyPropertyChangedEventArgs e)
-        {
-            if (IsInDesignMode(hostControl))
-            {
-                return;
-            }
-
-            RegisterNewPopupRegion(hostControl, e.NewValue as string);
-        }
-
-        private static bool IsInDesignMode(DependencyObject element)
-        {
-            // Due to a known issue in Cider, GetIsInDesignMode attached property value is not enough to know if it's in design mode.
-            return DesignerProperties.GetIsInDesignMode(element) || Application.Current == null
-                   || Application.Current.GetType() == typeof(Application);
-        }
-    }
-}

+ 0 - 83
CSharp/Infrastructure/ReturnCommandBehavior.cs

@@ -1,83 +0,0 @@
-//===================================================================================
-// Microsoft patterns & practices
-// Composite Application Guidance for Windows Presentation Foundation and Silverlight
-//===================================================================================
-// Copyright (c) Microsoft Corporation.  All rights reserved.
-// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
-// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
-// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
-// FITNESS FOR A PARTICULAR PURPOSE.
-//===================================================================================
-// The example companies, organizations, products, domain names,
-// e-mail addresses, logos, people, places, and events depicted
-// herein are fictitious.  No association with any real company,
-// organization, product, domain name, email address, logo, person,
-// places, or events is intended or should be inferred.
-//===================================================================================
-using System.Windows.Controls;
-using System.Windows.Input;
-using Microsoft.Practices.Prism.Commands;
-
-namespace Infrastructure
-{
-    /// <summary>
-    /// Defines a behavior that executes a <see cref="ICommand"/> when the Return key is pressed inside a <see cref="TextBox"/>.
-    /// </summary>
-    /// <remarks>This behavior also supports setting a basic watermark on the <see cref="TextBox"/>.</remarks>
-    public class ReturnCommandBehavior : CommandBehaviorBase<TextBox>
-    {
-        /// <summary>
-        /// Initializes a new instance of <see cref="ReturnCommandBehavior"/>.
-        /// </summary>
-        /// <param name="textBox">The <see cref="TextBox"/> over which the <see cref="ICommand"/> will work.</param>
-        public ReturnCommandBehavior(TextBox textBox)
-            : base(textBox)
-        {
-            textBox.AcceptsReturn = false;
-            textBox.KeyDown += (s, e) => this.KeyPressed(e.Key);
-            textBox.GotFocus += (s, e) => this.GotFocus();
-            textBox.LostFocus += (s, e) => this.LostFocus();
-        }
-
-        /// <summary>
-        /// Gets or Sets the text which is set as water mark on the <see cref="TextBox"/>.
-        /// </summary>
-        public string DefaultTextAfterCommandExecution { get; set; }
-
-        /// <summary>
-        /// Executes the <see cref="ICommand"/> when <paramref name="key"/> is <see cref="Key.Enter"/>.
-        /// </summary>
-        /// <param name="key">The key pressed on the <see cref="TextBox"/>.</param>
-        protected void KeyPressed(Key key)
-        {
-            if (key == Key.Enter && TargetObject != null)
-            {
-                this.CommandParameter = TargetObject.Text;
-                ExecuteCommand();
-
-                this.ResetText();
-            }
-        }
-
-        private void GotFocus()
-        {
-            if (TargetObject != null && TargetObject.Text == this.DefaultTextAfterCommandExecution)
-            {
-                this.ResetText();
-            }
-        }
-
-        private void ResetText()
-        {
-            TargetObject.Text = string.Empty;
-        }
-
-        private void LostFocus()
-        {
-            if (TargetObject != null && string.IsNullOrEmpty(TargetObject.Text) && this.DefaultTextAfterCommandExecution != null)
-            {
-                TargetObject.Text = this.DefaultTextAfterCommandExecution;
-            }
-        }
-    }
-}

+ 14 - 12
CSharp/Infrastructure/ViewExportAttribute.cs

@@ -19,18 +19,20 @@ using System.ComponentModel.Composition;
 
 namespace Infrastructure
 {
-    [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
-    [MetadataAttribute]
-    public class ViewExportAttribute : ExportAttribute, IViewRegionRegistration
-    {
-        public ViewExportAttribute()
-            : base(typeof(object))
-        { }
+	[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
+	[MetadataAttribute]
+	public class ViewExportAttribute : ExportAttribute, IViewRegionRegistration
+	{
+		public ViewExportAttribute() : base(typeof(object))
+		{ }
 
-        public ViewExportAttribute(string viewName)
-            : base(viewName, typeof(object))
-        { }
+		public ViewExportAttribute(string viewName) : base(viewName, typeof(object))
+		{ }
 
-        public string RegionName { get; set; }
-    }
+		public string RegionName 
+		{
+			get; 
+			set; 
+		}
+	}
 }

+ 0 - 33
CSharp/Infrastructure/WindowDialogActivationBehavior.Desktop.cs

@@ -1,33 +0,0 @@
-//===================================================================================
-// Microsoft patterns & practices
-// Composite Application Guidance for Windows Presentation Foundation and Silverlight
-//===================================================================================
-// Copyright (c) Microsoft Corporation.  All rights reserved.
-// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
-// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
-// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
-// FITNESS FOR A PARTICULAR PURPOSE.
-//===================================================================================
-// The example companies, organizations, products, domain names,
-// e-mail addresses, logos, people, places, and events depicted
-// herein are fictitious.  No association with any real company,
-// organization, product, domain name, email address, logo, person,
-// places, or events is intended or should be inferred.
-//===================================================================================
-namespace Infrastructure
-{
-    /// <summary>
-    /// Specifies the <see cref="DialogActivationBehavior"/> class for using the behavior on WPF.
-    /// </summary>
-    public class WindowDialogActivationBehavior : DialogActivationBehavior
-    {
-        /// <summary>
-        /// Creates a wrapper for the WPF <see cref="System.Windows.Window"/>.
-        /// </summary>
-        /// <returns>Instance of the <see cref="System.Windows.Window"/> wrapper.</returns>
-        protected override IWindow CreateWindow()
-        {
-            return new WindowWrapper();
-        }
-    }
-}

+ 0 - 89
CSharp/Infrastructure/WindowWrapper.Desktop.cs

@@ -1,89 +0,0 @@
-//===================================================================================
-// Microsoft patterns & practices
-// Composite Application Guidance for Windows Presentation Foundation and Silverlight
-//===================================================================================
-// Copyright (c) Microsoft Corporation.  All rights reserved.
-// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
-// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
-// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
-// FITNESS FOR A PARTICULAR PURPOSE.
-//===================================================================================
-// The example companies, organizations, products, domain names,
-// e-mail addresses, logos, people, places, and events depicted
-// herein are fictitious.  No association with any real company,
-// organization, product, domain name, email address, logo, person,
-// places, or events is intended or should be inferred.
-//===================================================================================
-using System;
-using System.Windows;
-
-namespace Infrastructure
-{
-    /// <summary>
-    /// Defines a wrapper for the <see cref="Window"/> class that implements the <see cref="IWindow"/> interface.
-    /// </summary>
-    public class WindowWrapper : IWindow
-    {
-        private readonly Window window;
-
-        /// <summary>
-        /// Initializes a new instance of <see cref="WindowWrapper"/>.
-        /// </summary>
-        public WindowWrapper()
-        {
-            this.window = new Window();
-        }
-
-        /// <summary>
-        /// Ocurrs when the <see cref="Window"/> is closed.
-        /// </summary>
-        public event EventHandler Closed
-        {
-            add { this.window.Closed += value; }
-            remove { this.window.Closed -= value; }
-        }
-
-        /// <summary>
-        /// Gets or Sets the content for the <see cref="Window"/>.
-        /// </summary>
-        public object Content
-        {
-            get { return this.window.Content; }
-            set { this.window.Content = value; }
-        }
-
-        /// <summary>
-        /// Gets or Sets the <see cref="Window.Owner"/> control of the <see cref="Window"/>.
-        /// </summary>
-        public object Owner
-        {
-            get { return this.window.Owner; }
-            set { this.window.Owner = value as Window; }
-        }
-
-        /// <summary>
-        /// Gets or Sets the <see cref="FrameworkElement.Style"/> to apply to the <see cref="Window"/>.
-        /// </summary>
-        public Style Style
-        {
-            get { return this.window.Style; }
-            set { this.window.Style = value; }
-        }
-
-        /// <summary>
-        /// Opens the <see cref="Window"/>.
-        /// </summary>
-        public void Show()
-        {
-            this.window.Show();
-        }
-
-        /// <summary>
-        /// Closes the <see cref="Window"/>.
-        /// </summary>
-        public void Close()
-        {
-            this.window.Close();
-        }
-    }
-}