client/src/Iri.Modernisation.Controls/View/ContextualBinderLayer/ContextualBinderLayer.xaml.cs
changeset 13 b5ee436add3d
parent 0 249d70e7b32d
child 28 2d4ec5ab2a40
--- a/client/src/Iri.Modernisation.Controls/View/ContextualBinderLayer/ContextualBinderLayer.xaml.cs	Tue Nov 24 10:42:26 2009 +0100
+++ b/client/src/Iri.Modernisation.Controls/View/ContextualBinderLayer/ContextualBinderLayer.xaml.cs	Wed Nov 25 09:39:26 2009 +0100
@@ -21,9 +21,11 @@
         private Line _linkLine;
         private bool _active = false;
         private System.Windows.Threading.DispatcherTimer myDispatcherTimer;
+        private Point _menuAnnotationPoint;
         public ContextualBinderLayer()
         {
             InitializeComponent();
+            Commands.PolemicElement.ElementSelected.Executed += new EventHandler<SLExtensions.Input.ExecutedEventArgs>(ElementSelected_Executed);
             Commands.ContextualBinderLayer.EndBind.Executed += new EventHandler<SLExtensions.Input.ExecutedEventArgs>(EndBind_Executed);
             MouseLeftButtonUp += new MouseButtonEventHandler(ContextualBinderLayer_MouseLeftButtonUp);
             MouseMove += new MouseEventHandler(ContextualBinderLayer_MouseMove);
@@ -33,6 +35,11 @@
             myDispatcherTimer.Tick +=new EventHandler(myDispatcherTimer_Tick);
         }
 
+        void ElementSelected_Executed(object sender, SLExtensions.Input.ExecutedEventArgs e)
+        {
+            _menuAnnotationPoint = ((MouseButtonEventArgs)e.Parameter).GetPosition(Application.Current.RootVisual);
+        }
+
         void  myDispatcherTimer_Tick(object sender, EventArgs e)
         {
  	          LayoutRoot.Background = PolemicTypeColorConverter.Convert(_movingBinder.PolemicType);
@@ -79,19 +86,28 @@
 
         void BeginBind_Executed(object sender, SLExtensions.Input.ExecutedEventArgs e)
         {
+            Point temp;
+            if(e.Source ==null)
+            {
+               temp = _menuAnnotationPoint;
+            }
+            else
+            {
+                temp  =  ((MouseButtonEventArgs)e.Source).GetPosition(Application.Current.RootVisual);
+            }
             LayoutRoot.Children.Clear();
             _movingBinder =new ContextualLinkBinder( ((ContextualLinkBinder)e.Parameter));  
             _movingBinder.Margin = new Thickness(
-             ((MouseButtonEventArgs)e.Source).GetPosition(this).X - _movingBinder.Width/ 2,
-             ((MouseButtonEventArgs)e.Source).GetPosition(this).Y - _movingBinder.Height/2 ,
+             temp.X - _movingBinder.Width/ 2,
+             temp.Y - _movingBinder.Height / 2,
               _movingBinder.Margin.Right,
                _movingBinder.Margin.Bottom);
             _linkLine = new Line()
             {
-                X1 = ((MouseButtonEventArgs)e.Source).GetPosition(this).X,
-                Y1 = ((MouseButtonEventArgs)e.Source).GetPosition(this).Y,
-                X2 = ((MouseButtonEventArgs)e.Source).GetPosition(this).X,
-                Y2 = ((MouseButtonEventArgs)e.Source).GetPosition(this).Y,
+                X1 = temp.X,
+                Y1 = temp.Y,
+                X2 = temp.X,
+                Y2 = temp.Y,
                 Stroke = PolemicTypeColorConverter.Convert(_movingBinder.PolemicType),
                 StrokeThickness = 2
             };