فهرست منبع

behavior view控件,用于处理创建行为树

tanghai 14 سال پیش
والد
کامیت
b9b60b7289

+ 15 - 0
CSharp/CSharp.sln

@@ -11,6 +11,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Infrastructure", "Infrastru
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TreeCanvas", "Modules\TreeCanvas\TreeCanvas.csproj", "{6CD185D1-08E0-4729-A999-2D5B57BA8193}"
 EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Controls", "Controls", "{EEC1B63E-05B1-4107-9627-B2542EED2B28}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BehaviorView", "Controls\BehaviorView\BehaviorView.csproj", "{844E644E-A19D-4BBA-9E20-287977E2564D}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -61,6 +65,16 @@ Global
 		{6CD185D1-08E0-4729-A999-2D5B57BA8193}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
 		{6CD185D1-08E0-4729-A999-2D5B57BA8193}.Release|Mixed Platforms.Build.0 = Release|Any CPU
 		{6CD185D1-08E0-4729-A999-2D5B57BA8193}.Release|x86.ActiveCfg = Release|Any CPU
+		{844E644E-A19D-4BBA-9E20-287977E2564D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{844E644E-A19D-4BBA-9E20-287977E2564D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{844E644E-A19D-4BBA-9E20-287977E2564D}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+		{844E644E-A19D-4BBA-9E20-287977E2564D}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+		{844E644E-A19D-4BBA-9E20-287977E2564D}.Debug|x86.ActiveCfg = Debug|Any CPU
+		{844E644E-A19D-4BBA-9E20-287977E2564D}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{844E644E-A19D-4BBA-9E20-287977E2564D}.Release|Any CPU.Build.0 = Release|Any CPU
+		{844E644E-A19D-4BBA-9E20-287977E2564D}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+		{844E644E-A19D-4BBA-9E20-287977E2564D}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+		{844E644E-A19D-4BBA-9E20-287977E2564D}.Release|x86.ActiveCfg = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE
@@ -68,5 +82,6 @@ Global
 	GlobalSection(NestedProjects) = preSolution
 		{7CC7BF9C-13BE-470E-BC35-6A1944767899} = {C4C64188-4FAE-4CC3-A9E6-D9D4AF7429B6}
 		{6CD185D1-08E0-4729-A999-2D5B57BA8193} = {C4C64188-4FAE-4CC3-A9E6-D9D4AF7429B6}
+		{844E644E-A19D-4BBA-9E20-287977E2564D} = {EEC1B63E-05B1-4107-9627-B2542EED2B28}
 	EndGlobalSection
 EndGlobal

+ 12 - 0
CSharp/Controls/BehaviorView/BehaviorNode.cs

@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Windows.Controls;
+
+namespace Controls.BehaviorView
+{
+	public class BehaviorNode: ListBoxItem
+	{
+	}
+}

+ 469 - 0
CSharp/Controls/BehaviorView/BehaviorView.cs

@@ -0,0 +1,469 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+
+namespace Controls.BehaviorView
+{
+	/// <summary>
+	/// 按照步骤 1a 或 1b 操作,然后执行步骤 2 以在 XAML 文件中使用此自定义控件。
+	///
+	/// 步骤 1a) 在当前项目中存在的 XAML 文件中使用该自定义控件。
+	/// 将此 XmlNamespace 特性添加到要使用该特性的标记文件的根 
+	/// 元素中:
+	///
+	///     xmlns:MyNamespace="clr-namespace:BehaviorView"
+	///
+	///
+	/// 步骤 1b) 在其他项目中存在的 XAML 文件中使用该自定义控件。
+	/// 将此 XmlNamespace 特性添加到要使用该特性的标记文件的根 
+	/// 元素中:
+	///
+	///     xmlns:MyNamespace="clr-namespace:BehaviorView;assembly=BehaviorView"
+	///
+	/// 您还需要添加一个从 XAML 文件所在的项目到此项目的项目引用,
+	/// 并重新生成以避免编译错误:
+	///
+	///     在解决方案资源管理器中右击目标项目,然后依次单击
+	///     “添加引用”->“项目”->[选择此项目]
+	///
+	///
+	/// 步骤 2)
+	/// 继续操作并在 XAML 文件中使用控件。
+	///
+	///     <MyNamespace:CustomControl1/>
+	///
+	/// </summary>
+	/// <summary>
+	/// A Canvas which manages dragging of the UIElements it contains.  
+	/// </summary>
+	public class BehaviorView : Canvas
+	{
+		// Stores a reference to the UIElement currently being dragged by the user.
+		private UIElement elementBeingDragged;
+
+		// Keeps track of where the mouse cursor was when a drag operation began.		
+		private Point origCursorLocation;
+
+		// The offsets from the DragCanvas' edges when the drag operation began.
+		private double origHorizOffset, origVertOffset;
+
+		// Keeps track of which horizontal and vertical offset should be modified for the drag element.
+		private bool modifyLeftOffset, modifyTopOffset;
+
+		// True if a drag operation is underway, else false.
+		private bool isDragInProgress;
+
+		public static readonly DependencyProperty CanBeDraggedProperty;
+
+		public static bool GetCanBeDragged(UIElement uiElement)
+		{
+			if (uiElement == null)
+				return false;
+
+			return (bool)uiElement.GetValue(CanBeDraggedProperty);
+		}
+
+		public static void SetCanBeDragged(UIElement uiElement, bool value)
+		{
+			if (uiElement != null)
+				uiElement.SetValue(CanBeDraggedProperty, value);
+		}
+
+		public static readonly DependencyProperty AllowDraggingProperty;
+		public static readonly DependencyProperty AllowDragOutOfViewProperty;
+
+		static BehaviorView()
+		{
+			AllowDraggingProperty = DependencyProperty.Register(
+				"AllowDragging",
+				typeof(bool),
+				typeof(BehaviorView),
+				new PropertyMetadata(true));
+
+			AllowDragOutOfViewProperty = DependencyProperty.Register(
+				"AllowDragOutOfView",
+				typeof(bool),
+				typeof(BehaviorView),
+				new UIPropertyMetadata(false));
+
+			CanBeDraggedProperty = DependencyProperty.RegisterAttached(
+				"CanBeDragged",
+				typeof(bool),
+				typeof(BehaviorView),
+				new UIPropertyMetadata(true));
+		}
+
+		/// <summary>
+		/// Initializes a new instance of DragCanvas.  UIElements in
+		/// the DragCanvas will immediately be draggable by the user.
+		/// </summary>
+		public BehaviorView()
+		{
+		}
+
+		/// <summary>
+		/// Gets/sets whether elements in the DragCanvas should be draggable by the user.
+		/// The default value is true.  This is a dependency property.
+		/// </summary>
+		public bool AllowDragging
+		{
+			get { return (bool)base.GetValue(AllowDraggingProperty); }
+			set { base.SetValue(AllowDraggingProperty, value); }
+		}
+
+		/// <summary>
+		/// Gets/sets whether the user should be able to drag elements in the DragCanvas out of
+		/// the viewable area.  The default value is false.  This is a dependency property.
+		/// </summary>
+		public bool AllowDragOutOfView
+		{
+			get { return (bool)GetValue(AllowDragOutOfViewProperty); }
+			set { SetValue(AllowDragOutOfViewProperty, value); }
+		}
+
+		/// <summary>
+		/// Assigns the element a z-index which will ensure that 
+		/// it is in front of every other element in the Canvas.
+		/// The z-index of every element whose z-index is between 
+		/// the element's old and new z-index will have its z-index 
+		/// decremented by one.
+		/// </summary>
+		/// <param name="targetElement">
+		/// The element to be sent to the front of the z-order.
+		/// </param>
+		public void BringToFront(UIElement element)
+		{
+			this.UpdateZOrder(element, true);
+		}
+
+		/// <summary>
+		/// Assigns the element a z-index which will ensure that 
+		/// it is behind every other element in the Canvas.
+		/// The z-index of every element whose z-index is between 
+		/// the element's old and new z-index will have its z-index 
+		/// incremented by one.
+		/// </summary>
+		/// <param name="targetElement">
+		/// The element to be sent to the back of the z-order.
+		/// </param>
+		public void SendToBack(UIElement element)
+		{
+			this.UpdateZOrder(element, false);
+		}
+
+		/// <summary>
+		/// Returns the UIElement currently being dragged, or null.
+		/// </summary>
+		/// <remarks>
+		/// Note to inheritors: This property exposes a protected 
+		/// setter which should be used to modify the drag element.
+		/// </remarks>
+		public UIElement ElementBeingDragged
+		{
+			get
+			{
+				if (!this.AllowDragging)
+					return null;
+				else
+					return this.elementBeingDragged;
+			}
+			protected set
+			{
+				if (this.elementBeingDragged != null)
+					this.elementBeingDragged.ReleaseMouseCapture();
+
+				if (!this.AllowDragging)
+					this.elementBeingDragged = null;
+				else
+				{
+					if (BehaviorView.GetCanBeDragged(value))
+					{
+						this.elementBeingDragged = value;
+						this.elementBeingDragged.CaptureMouse();
+					}
+					else
+						this.elementBeingDragged = null;
+				}
+			}
+		}
+
+		/// <summary>
+		/// Walks up the visual tree starting with the specified DependencyObject, 
+		/// looking for a UIElement which is a child of the Canvas.  If a suitable 
+		/// element is not found, null is returned.  If the 'depObj' object is a 
+		/// UIElement in the Canvas's Children collection, it will be returned.
+		/// </summary>
+		/// <param name="depObj">
+		/// A DependencyObject from which the search begins.
+		/// </param>
+		public UIElement FindCanvasChild(DependencyObject depObj)
+		{
+			while (depObj != null)
+			{
+				// If the current object is a UIElement which is a child of the
+				// Canvas, exit the loop and return it.
+				UIElement elem = depObj as UIElement;
+				if (elem != null && base.Children.Contains(elem))
+					break;
+
+				// VisualTreeHelper works with objects of type Visual or Visual3D.
+				// If the current object is not derived from Visual or Visual3D,
+				// then use the LogicalTreeHelper to find the parent element.
+				if (depObj is Visual || depObj is Visual3D)
+					depObj = VisualTreeHelper.GetParent(depObj);
+				else
+					depObj = LogicalTreeHelper.GetParent(depObj);
+			}
+			return depObj as UIElement;
+		}
+
+		protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)
+		{
+			base.OnPreviewMouseLeftButtonDown(e);
+
+			this.isDragInProgress = false;
+
+			// Cache the mouse cursor location.
+			this.origCursorLocation = e.GetPosition(this);
+
+			// Walk up the visual tree from the element that was clicked, 
+			// looking for an element that is a direct child of the Canvas.
+			this.ElementBeingDragged = this.FindCanvasChild(e.Source as DependencyObject);
+			if (this.ElementBeingDragged == null)
+				return;
+
+			// Get the element's offsets from the four sides of the Canvas.
+			double left = Canvas.GetLeft(this.ElementBeingDragged);
+			double right = Canvas.GetRight(this.ElementBeingDragged);
+			double top = Canvas.GetTop(this.ElementBeingDragged);
+			double bottom = Canvas.GetBottom(this.ElementBeingDragged);
+
+			// Calculate the offset deltas and determine for which sides
+			// of the Canvas to adjust the offsets.
+			this.origHorizOffset = ResolveOffset(left, right, out this.modifyLeftOffset);
+			this.origVertOffset = ResolveOffset(top, bottom, out this.modifyTopOffset);
+
+			// Set the Handled flag so that a control being dragged 
+			// does not react to the mouse input.
+			e.Handled = true;
+
+			this.isDragInProgress = true;
+		}
+
+		protected override void OnPreviewMouseMove(MouseEventArgs e)
+		{
+			base.OnPreviewMouseMove(e);
+
+			// If no element is being dragged, there is nothing to do.
+			if (this.ElementBeingDragged == null || !this.isDragInProgress)
+				return;
+
+			// Get the position of the mouse cursor, relative to the Canvas.
+			Point cursorLocation = e.GetPosition(this);
+
+			// These values will store the new offsets of the drag element.
+			double newHorizontalOffset, newVerticalOffset;
+
+			// Determine the horizontal offset.
+			if (this.modifyLeftOffset)
+				newHorizontalOffset = this.origHorizOffset + (cursorLocation.X - this.origCursorLocation.X);
+			else
+				newHorizontalOffset = this.origHorizOffset - (cursorLocation.X - this.origCursorLocation.X);
+
+			// Determine the vertical offset.
+			if (this.modifyTopOffset)
+				newVerticalOffset = this.origVertOffset + (cursorLocation.Y - this.origCursorLocation.Y);
+			else
+				newVerticalOffset = this.origVertOffset - (cursorLocation.Y - this.origCursorLocation.Y);
+
+			if (!this.AllowDragOutOfView)
+			{
+				// Get the bounding rect of the drag element.
+				Rect elemRect = this.CalculateDragElementRect(newHorizontalOffset, newVerticalOffset);
+
+				//
+				// If the element is being dragged out of the viewable area, 
+				// determine the ideal rect location, so that the element is 
+				// within the edge(s) of the canvas.
+				//
+				bool leftAlign = elemRect.Left < 0;
+				bool rightAlign = elemRect.Right > this.ActualWidth;
+
+				if (leftAlign)
+					newHorizontalOffset = modifyLeftOffset ? 0 : this.ActualWidth - elemRect.Width;
+				else if (rightAlign)
+					newHorizontalOffset = modifyLeftOffset ? this.ActualWidth - elemRect.Width : 0;
+
+				bool topAlign = elemRect.Top < 0;
+				bool bottomAlign = elemRect.Bottom > this.ActualHeight;
+
+				if (topAlign)
+					newVerticalOffset = modifyTopOffset ? 0 : this.ActualHeight - elemRect.Height;
+				else if (bottomAlign)
+					newVerticalOffset = modifyTopOffset ? this.ActualHeight - elemRect.Height : 0;
+			}
+
+			if (this.modifyLeftOffset)
+				Canvas.SetLeft(this.ElementBeingDragged, newHorizontalOffset);
+			else
+				Canvas.SetRight(this.ElementBeingDragged, newHorizontalOffset);
+
+			if (this.modifyTopOffset)
+				Canvas.SetTop(this.ElementBeingDragged, newVerticalOffset);
+			else
+				Canvas.SetBottom(this.ElementBeingDragged, newVerticalOffset);
+		}
+
+		protected override void OnPreviewMouseUp(MouseButtonEventArgs e)
+		{
+			base.OnPreviewMouseUp(e);
+
+			// Reset the field whether the left or right mouse button was 
+			// released, in case a context menu was opened on the drag element.
+			this.ElementBeingDragged = null;
+		}
+
+		/// <summary>
+		/// Returns a Rect which describes the bounds of the element being dragged.
+		/// </summary>
+		private Rect CalculateDragElementRect(double newHorizOffset, double newVertOffset)
+		{
+			if (this.ElementBeingDragged == null)
+				throw new InvalidOperationException("ElementBeingDragged is null.");
+
+			Size elemSize = this.ElementBeingDragged.RenderSize;
+
+			double x, y;
+
+			if (this.modifyLeftOffset)
+				x = newHorizOffset;
+			else
+				x = this.ActualWidth - newHorizOffset - elemSize.Width;
+
+			if (this.modifyTopOffset)
+				y = newVertOffset;
+			else
+				y = this.ActualHeight - newVertOffset - elemSize.Height;
+
+			Point elemLoc = new Point(x, y);
+
+			return new Rect(elemLoc, elemSize);
+		}
+
+		/// <summary>
+		/// Determines one component of a UIElement's location 
+		/// within a Canvas (either the horizontal or vertical offset).
+		/// </summary>
+		/// <param name="side1">
+		/// The value of an offset relative to a default side of the 
+		/// Canvas (i.e. top or left).
+		/// </param>
+		/// <param name="side2">
+		/// The value of the offset relative to the other side of the 
+		/// Canvas (i.e. bottom or right).
+		/// </param>
+		/// <param name="useSide1">
+		/// Will be set to true if the returned value should be used 
+		/// for the offset from the side represented by the 'side1' 
+		/// parameter.  Otherwise, it will be set to false.
+		/// </param>
+		private static double ResolveOffset(double side1, double side2, out bool useSide1)
+		{
+			// If the Canvas.Left and Canvas.Right attached properties 
+			// are specified for an element, the 'Left' value is honored.
+			// The 'Top' value is honored if both Canvas.Top and 
+			// Canvas.Bottom are set on the same element.  If one 
+			// of those attached properties is not set on an element, 
+			// the default value is Double.NaN.
+			useSide1 = true;
+			double result;
+			if (Double.IsNaN(side1))
+			{
+				if (Double.IsNaN(side2))
+				{
+					// Both sides have no value, so set the
+					// first side to a value of zero.
+					result = 0;
+				}
+				else
+				{
+					result = side2;
+					useSide1 = false;
+				}
+			}
+			else
+			{
+				result = side1;
+			}
+			return result;
+		}
+
+		/// <summary>
+		/// Helper method used by the BringToFront and SendToBack methods.
+		/// </summary>
+		/// <param name="element">
+		/// The element to bring to the front or send to the back.
+		/// </param>
+		/// <param name="bringToFront">
+		/// Pass true if calling from BringToFront, else false.
+		/// </param>
+		private void UpdateZOrder(UIElement element, bool bringToFront)
+		{
+
+			if (element == null)
+				throw new ArgumentNullException("element");
+
+			if (!base.Children.Contains(element))
+				throw new ArgumentException("Must be a child element of the Canvas.", "element");
+
+			// Determine the Z-Index for the target UIElement.
+			int elementNewZIndex = -1;
+			if (bringToFront)
+			{
+				foreach (UIElement elem in base.Children)
+					if (elem.Visibility != Visibility.Collapsed)
+						++elementNewZIndex;
+			}
+			else
+			{
+				elementNewZIndex = 0;
+			}
+
+			// Determine if the other UIElements' Z-Index 
+			// should be raised or lowered by one. 
+			int offset = (elementNewZIndex == 0) ? +1 : -1;
+
+			int elementCurrentZIndex = Canvas.GetZIndex(element);
+
+
+			// Update the Z-Index of every UIElement in the Canvas.
+			foreach (UIElement childElement in base.Children)
+			{
+				if (childElement == element)
+					Canvas.SetZIndex(element, elementNewZIndex);
+				else
+				{
+					int zIndex = Canvas.GetZIndex(childElement);
+
+					// Only modify the z-index of an element if it is  
+					// in between the target element's old and new z-index.
+					if (bringToFront && elementCurrentZIndex < zIndex ||
+						!bringToFront && zIndex < elementCurrentZIndex)
+					{
+						Canvas.SetZIndex(childElement, zIndex + offset);
+					}
+				}
+			}
+		}
+	}
+}

+ 76 - 0
CSharp/Controls/BehaviorView/BehaviorView.csproj

@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProductVersion>8.0.30703</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{844E644E-A19D-4BBA-9E20-287977E2564D}</ProjectGuid>
+    <OutputType>library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>BehaviorView</RootNamespace>
+    <AssemblyName>BehaviorView</AssemblyName>
+    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+    <TargetFrameworkProfile>Client</TargetFrameworkProfile>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Xml" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="System.Xaml">
+      <RequiredTargetFramework>4.0</RequiredTargetFramework>
+    </Reference>
+    <Reference Include="WindowsBase" />
+    <Reference Include="PresentationCore" />
+    <Reference Include="PresentationFramework" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="ConnectPoint.cs" />
+    <Compile Include="BehaviorNode.cs" />
+    <Page Include="Themes\Generic.xaml">
+      <Generator>MSBuild:Compile</Generator>
+      <SubType>Designer</SubType>
+    </Page>
+    <Compile Include="BehaviorView.cs">
+      <SubType>Code</SubType>
+    </Compile>
+  </ItemGroup>
+  <ItemGroup>
+    <AppDesigner Include="Properties\" />
+  </ItemGroup>
+  <ItemGroup>
+    <Folder Include="Properties\" />
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+</Project>

+ 11 - 0
CSharp/Controls/BehaviorView/ConnectPoint.cs

@@ -0,0 +1,11 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Controls.BehaviorView
+{
+	public class ConnectPoint
+	{
+	}
+}

+ 5 - 0
CSharp/Controls/BehaviorView/Themes/Generic.xaml

@@ -0,0 +1,5 @@
+<ResourceDictionary
+	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+	xmlns:local="clr-namespace:Controls.BehaviorView">
+</ResourceDictionary>

+ 3 - 0
CSharp/Editor/Editor.csproj

@@ -15,6 +15,8 @@
     <FileAlignment>512</FileAlignment>
     <ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
     <WarningLevel>4</WarningLevel>
+    <Utf8Output>true</Utf8Output>
+    <ExpressionBlendVersion>4.0.20621.0</ExpressionBlendVersion>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
     <PlatformTarget>x86</PlatformTarget>
@@ -36,6 +38,7 @@
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
   <ItemGroup>
+    <Reference Include="Microsoft.Expression.Drawing" />
     <Reference Include="Microsoft.Practices.Prism">
       <HintPath>..\Packages\Prism.4.0.0.0\lib\NET40\Microsoft.Practices.Prism.dll</HintPath>
     </Reference>

+ 1 - 1
CSharp/Editor/NLog.config

@@ -3,7 +3,7 @@
 		xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 	<targets>
 		<target name="file" xsi:type="File" fileName="${basedir}/Log.txt"
-				layout="${longdate} ${threadid:padCharacter=0:padding=4:fixedLength=true} ${callsite:className=false:includeSourcePath=false:methodName=false:fileName=true}] ${message}"/>
+				layout="${longdate} ${threadid:padCharacter=0:padding=4:fixedLength=true} ${callsite:className=false:includeSourcePath=false:methodName=false:fileName=true}  ${message}"/>
 	</targets>
 	<rules>
 		<logger name="*" minlevel="Trace" writeTo="file"/>

+ 2 - 4
CSharp/Editor/Shell.xaml

@@ -3,10 +3,8 @@
 		xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 		xmlns:cal="http://www.codeplex.com/CompositeWPF"
 		xmlns:prism="http://www.codeplex.com/prism"
-		Title="Editor" Height="600" Width="800" WindowStartupLocation="CenterScreen">
+		Title="Editor" Height="800" Width="1280" WindowStartupLocation="CenterScreen">
 	<Grid>
-		<StackPanel>
-			<ContentControl Name="mainRegion" prism:RegionManager.RegionName="MainRegion" />
-		</StackPanel>
+		<ContentControl Name="treeCanvas" prism:RegionManager.RegionName="TreeCanvasRegion" />
 	</Grid>
 </Window>

+ 0 - 1
CSharp/Modules/LoginModule/LoginViewModel.cs

@@ -1,6 +1,5 @@
 using System.ComponentModel.Composition;
 using Microsoft.Practices.Prism.ViewModel;
-using Microsoft.Practices.Prism.Commands;
 using System.Threading.Tasks;
 using System.Net.Sockets;
 using System.Security.Cryptography;

+ 7 - 0
CSharp/Modules/TreeCanvas/TreeCanvas.csproj

@@ -12,6 +12,8 @@
     <AssemblyName>TreeCanvas</AssemblyName>
     <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
     <FileAlignment>512</FileAlignment>
+    <Utf8Output>true</Utf8Output>
+    <ExpressionBlendVersion>4.0.20621.0</ExpressionBlendVersion>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
     <DebugSymbols>true</DebugSymbols>
@@ -31,6 +33,7 @@
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
   <ItemGroup>
+    <Reference Include="Microsoft.Expression.Drawing" />
     <Reference Include="Microsoft.Practices.Prism">
       <HintPath>..\..\Packages\Prism.4.0.0.0\lib\NET40\Microsoft.Practices.Prism.dll</HintPath>
     </Reference>
@@ -73,6 +76,10 @@
     </Page>
   </ItemGroup>
   <ItemGroup>
+    <ProjectReference Include="..\..\Controls\BehaviorView\BehaviorView.csproj">
+      <Project>{844E644E-A19D-4BBA-9E20-287977E2564D}</Project>
+      <Name>BehaviorView</Name>
+    </ProjectReference>
     <ProjectReference Include="..\..\Infrastructure\Infrastructure.csproj">
       <Project>{48A2E149-0DAC-41B4-BB54-DFBCCD6D42B3}</Project>
       <Name>Infrastructure</Name>

+ 30 - 11
CSharp/Modules/TreeCanvas/TreeCanvasView.xaml

@@ -1,11 +1,30 @@
-<UserControl x:Class="Module.TreeCanvas.TreeCanvasView"
-		xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
-		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">
-	<Grid>
-
-	</Grid>
-</UserControl>
+<UserControl
+		xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+		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" 
+		xmlns:ed="http://schemas.microsoft.com/expression/2010/drawing" x:Class="Module.TreeCanvas.TreeCanvasView" 
+		mc:Ignorable="d" 
+		d:DesignHeight="600" d:DesignWidth="800" xmlns:my="clr-namespace:Controls.BehaviorView;assembly=BehaviorView">
+	<UserControl.Resources>
+		<RoutedUICommand x:Key="Commands.DeleteSelectedNodes" />
+		<RoutedUICommand x:Key="Commands.CreateNode" />
+	</UserControl.Resources>
+
+	<UserControl.CommandBindings>
+		<CommandBinding Command="{StaticResource Commands.DeleteSelectedNodes}" Executed="DeleteSelectedNodes_Executed" />
+		<CommandBinding Command="{StaticResource Commands.CreateNode}" Executed="CreateNode_Executed" />
+	</UserControl.CommandBindings>
+
+	<UserControl.ContextMenu>
+		<ContextMenu>
+			<MenuItem Header="Create Node" Command="{StaticResource Commands.CreateNode}" ToolTip="Creates a new node" />
+		</ContextMenu>
+	</UserControl.ContextMenu>
+	
+	<Canvas>
+		<TextBox Canvas.Left="296" Canvas.Top="271" Height="23" Name="textBox1" Width="120" />
+		<my:BehaviorNode Canvas.Left="279" Canvas.Top="151" Content="ListBoxItem" Height="42" Name="behaviorNode1" Width="120" />
+	</Canvas>
+	
+</UserControl>

+ 54 - 44
CSharp/Modules/TreeCanvas/TreeCanvasView.xaml.cs

@@ -1,44 +1,54 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Data;
-using System.Windows.Documents;
-using System.Windows.Input;
-using System.Windows.Media;
-using System.Windows.Media.Imaging;
-using System.Windows.Navigation;
-using System.Windows.Shapes;
-using System.ComponentModel.Composition;
-using Infrastructure;
-
-namespace Module.TreeCanvas
-{
-	/// <summary>
-	/// TreeCanvasView.xaml 的交互逻辑
-	/// </summary>
-	[ViewExport(RegionName = "TreeCanvasRegion")]
-	[PartCreationPolicy(CreationPolicy.NonShared)]
-	public partial class TreeCanvasView : UserControl
-	{
-		public TreeCanvasView()
-		{
-			InitializeComponent();
-		}
-
-		[Import]
-		TreeCanvasViewModel ViewModel
-		{
-			get
-			{
-				return this.DataContext as TreeCanvasViewModel;
-			}
-			set
-			{
-				this.DataContext = value;
-			}
-		}
-	}
-}
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+using System.ComponentModel.Composition;
+using Infrastructure;
+
+namespace Module.TreeCanvas
+{
+	/// <summary>
+	/// TreeCanvasView.xaml 的交互逻辑
+	/// </summary>
+	[ViewExport(RegionName = "TreeCanvasRegion")]
+	[PartCreationPolicy(CreationPolicy.NonShared)]
+	public partial class TreeCanvasView : UserControl
+	{
+		public TreeCanvasView()
+		{
+			InitializeComponent();
+		}
+
+		[Import]
+		TreeCanvasViewModel ViewModel
+		{
+			get
+			{
+				return this.DataContext as TreeCanvasViewModel;
+			}
+			set
+			{
+				this.DataContext = value;
+			}
+		}
+
+		private void DeleteSelectedNodes_Executed(object sender, ExecutedRoutedEventArgs e)
+		{
+
+		}
+
+		private void CreateNode_Executed(object sender, ExecutedRoutedEventArgs e)
+		{
+
+		}
+	}
+}

+ 14 - 7
CSharp/Modules/TreeCanvas/TreeCanvasViewModel.cs

@@ -1,11 +1,18 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
+using System.ComponentModel.Composition;
+using Microsoft.Practices.Prism.ViewModel;
+using NLog;
 
 namespace Module.TreeCanvas
-{
-	class TreeCanvasViewModel
-	{
+{
+	[Export(typeof(TreeCanvasViewModel))]
+	[PartCreationPolicy(CreationPolicy.NonShared)]
+	class TreeCanvasViewModel : NotificationObject
+	{
+		private Logger logger = LogManager.GetCurrentClassLogger();
+		public TreeCanvasViewModel()
+		{
+			logger.Debug("11111");
+		}
 	}
 }
+