ucNode.xaml.cs 4.52 KB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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 RoboforkApp
{
    /// <summary>
    /// Interaction logic for ucNode.xaml
    /// </summary>
    public partial class ucNode : UserControl
    {
        public ucNode()
        {
            InitializeComponent();
        }

        private bool _isFocus = false;
        private bool _isDragDelta = false;

        public static readonly DependencyProperty buttTextProperty =
        DependencyProperty.Register("txtNode", typeof(String),
        typeof(ucNode), new FrameworkPropertyMetadata(string.Empty));

        public static readonly DependencyProperty btnWidthProperty =
        DependencyProperty.Register("btnWidth", typeof(double),
        typeof(ucNode), new FrameworkPropertyMetadata(10.0));

        public static readonly DependencyProperty btnHeightProperty =
        DependencyProperty.Register("btnHeight", typeof(double),
        typeof(ucNode), new FrameworkPropertyMetadata(10.0));

        public static readonly DependencyProperty coordStringProperty =
        DependencyProperty.Register("coordString", typeof(String),
        typeof(ucNode), new FrameworkPropertyMetadata(string.Empty));

        public static readonly DependencyProperty fillColorProperty =
        DependencyProperty.Register("fillColor", typeof(String),
        typeof(ucNode), new FrameworkPropertyMetadata("Blue"));

      
        public String txtNode
        {
            get { return GetValue(buttTextProperty).ToString(); }
            set { SetValue(buttTextProperty, value); }
        }


        public double btnWidth
        {
            get { return (double)GetValue(btnWidthProperty); }
            set { SetValue(btnWidthProperty, value); }

        }

        public double btnHeight
        {
            get { return (double)GetValue(btnHeightProperty); }
            set { SetValue(btnHeightProperty, value); }

        }
        public String coordString
        {
            get { return GetValue(coordStringProperty).ToString(); }
            set { SetValue(coordStringProperty, value); }
        }

        public String fillColor
        {
            get { return GetValue(fillColorProperty).ToString(); }
            set { SetValue(fillColorProperty, value); }
        }


        public bool IsFocus
        {
            get { return _isFocus; }
            set { _isFocus = value; }
        }

        public bool IsDragDelta
        {
            get { return _isDragDelta; }
            set { _isDragDelta = value; }
        }

        private void btnHello_MouseDown(object sender, MouseButtonEventArgs e)
        {
            _isFocus = true;
        }

        private void btnHello_MouseUp(object sender, MouseButtonEventArgs e)
        {

        }

        private void btnHello_MouseMove(object sender, MouseEventArgs e)
        {

        }

        private void tmbThumb_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
        {

            if (_isDragDelta)
            {
                double left = Canvas.GetLeft(this);
                double top = Canvas.GetTop(this);
                if (0 < (top + e.VerticalChange)
                    && (top + e.VerticalChange) < (1000 - btnHeight))
                {
                    Canvas.SetTop(this, top + e.VerticalChange);
                }
                if (0 < (left + e.HorizontalChange)
                    && (left + e.HorizontalChange) < (1000 - btnWidth))
                {
                    Canvas.SetLeft(this, left + e.HorizontalChange);
                }

                DesignerCanvas.DragDeltaFlag = true;
                UpdateCoordString(left, top);
            }
        }

        private void UpdateCoordString(double left, double top)
        {
            coordString = "(" + Math.Round((left + btnWidth / 2), 2) + "," + Math.Round((top + btnHeight / 2), 2) + ")";
        }

        private void tmbThumb_DragCompleted(object sender, System.Windows.Controls.Primitives.DragCompletedEventArgs e)
        {
            coordString = String.Empty;
        }

        private void tmbThumb_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            if (_isDragDelta)
            {
                DesignerCanvas.EditNodeFlag = true;
            }
        }

    }
}