client/src/Iri.Modernisation.Controls/View/ContextualBinderLayer/ContextualBinderLayer.xaml.cs
changeset 0 249d70e7b32d
child 13 b5ee436add3d
equal deleted inserted replaced
-1:000000000000 0:249d70e7b32d
       
     1 using System;
       
     2 using System.Collections.Generic;
       
     3 using System.Linq;
       
     4 using System.Net;
       
     5 using System.Windows;
       
     6 using System.Windows.Controls;
       
     7 using System.Windows.Documents;
       
     8 using System.Windows.Input;
       
     9 using System.Windows.Media;
       
    10 using System.Windows.Media.Animation;
       
    11 using System.Windows.Shapes;
       
    12 using System.Threading;
       
    13 using Iri.Modernisation.BaseMVVM.Commands;
       
    14 using Iri.Modernisation.Controls.Converter;
       
    15 using Iri.Modernisation.Data.Models;
       
    16 namespace Iri.Modernisation.Controls.View
       
    17 {
       
    18     public partial class ContextualBinderLayer : UserControl
       
    19     {
       
    20         private ContextualLinkBinder _movingBinder;
       
    21         private Line _linkLine;
       
    22         private bool _active = false;
       
    23         private System.Windows.Threading.DispatcherTimer myDispatcherTimer;
       
    24         public ContextualBinderLayer()
       
    25         {
       
    26             InitializeComponent();
       
    27             Commands.ContextualBinderLayer.EndBind.Executed += new EventHandler<SLExtensions.Input.ExecutedEventArgs>(EndBind_Executed);
       
    28             MouseLeftButtonUp += new MouseButtonEventHandler(ContextualBinderLayer_MouseLeftButtonUp);
       
    29             MouseMove += new MouseEventHandler(ContextualBinderLayer_MouseMove);
       
    30             Commands.ContextualBinderLayer.BeginBind.Executed += new EventHandler<SLExtensions.Input.ExecutedEventArgs>(BeginBind_Executed);  
       
    31             myDispatcherTimer = new System.Windows.Threading.DispatcherTimer();
       
    32             myDispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 0);
       
    33             myDispatcherTimer.Tick +=new EventHandler(myDispatcherTimer_Tick);
       
    34         }
       
    35 
       
    36         void  myDispatcherTimer_Tick(object sender, EventArgs e)
       
    37         {
       
    38  	          LayoutRoot.Background = PolemicTypeColorConverter.Convert(_movingBinder.PolemicType);
       
    39                     LayoutRoot.Background.Opacity = 0.0;
       
    40                     _movingBinder.Visibility = Visibility.Visible;
       
    41                     _linkLine.Visibility = Visibility.Visible;
       
    42         }
       
    43         void EndBind_Executed(object sender, SLExtensions.Input.ExecutedEventArgs e)
       
    44         {
       
    45             if (_active)
       
    46             {
       
    47                 FlushDisplay();
       
    48             }
       
    49         }
       
    50         
       
    51         void ContextualBinderLayer_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
       
    52         {
       
    53             FlushDisplay();
       
    54         }
       
    55         private void FlushDisplay()
       
    56         {
       
    57             LayoutRoot.Children.Clear();
       
    58             _movingBinder.ReleaseMouseCapture();
       
    59             LayoutRoot.Background = null;
       
    60             _active = false;
       
    61             myDispatcherTimer.Stop();
       
    62             Commands.ContextualBinderLayer.DesactiveBind.Execute();
       
    63         }
       
    64        
       
    65         void ContextualBinderLayer_MouseMove(object sender, MouseEventArgs e)
       
    66         { 
       
    67             LayoutRoot.Background = null;
       
    68             _movingBinder.Visibility = Visibility.Collapsed;
       
    69             _linkLine.Visibility = Visibility.Collapsed;
       
    70             LayoutRoot.UpdateLayout();
       
    71             _movingBinder.Margin = new Thickness(
       
    72                                        e.GetPosition(this).X - _movingBinder.Width/2,
       
    73                                        e.GetPosition(this).Y - _movingBinder.Height / 2,
       
    74                                         0,
       
    75                                         0);
       
    76             _linkLine.X2 = e.GetPosition(this).X ;
       
    77             _linkLine.Y2 = e.GetPosition(this).Y;
       
    78         }
       
    79 
       
    80         void BeginBind_Executed(object sender, SLExtensions.Input.ExecutedEventArgs e)
       
    81         {
       
    82             LayoutRoot.Children.Clear();
       
    83             _movingBinder =new ContextualLinkBinder( ((ContextualLinkBinder)e.Parameter));  
       
    84             _movingBinder.Margin = new Thickness(
       
    85              ((MouseButtonEventArgs)e.Source).GetPosition(this).X - _movingBinder.Width/ 2,
       
    86              ((MouseButtonEventArgs)e.Source).GetPosition(this).Y - _movingBinder.Height/2 ,
       
    87               _movingBinder.Margin.Right,
       
    88                _movingBinder.Margin.Bottom);
       
    89             _linkLine = new Line()
       
    90             {
       
    91                 X1 = ((MouseButtonEventArgs)e.Source).GetPosition(this).X,
       
    92                 Y1 = ((MouseButtonEventArgs)e.Source).GetPosition(this).Y,
       
    93                 X2 = ((MouseButtonEventArgs)e.Source).GetPosition(this).X,
       
    94                 Y2 = ((MouseButtonEventArgs)e.Source).GetPosition(this).Y,
       
    95                 Stroke = PolemicTypeColorConverter.Convert(_movingBinder.PolemicType),
       
    96                 StrokeThickness = 2
       
    97             };
       
    98             LayoutRoot.Background = PolemicTypeColorConverter.Convert(_movingBinder.PolemicType);
       
    99             LayoutRoot.Background.Opacity = 0.0;
       
   100             LayoutRoot.Children.Add(_movingBinder);
       
   101             LayoutRoot.Children.Add(_linkLine);
       
   102             _active = true;
       
   103             Commands.ContextualBinderLayer.ActiveBind.Execute();
       
   104             myDispatcherTimer.Start();  
       
   105         }
       
   106     }
       
   107 }