aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/SideChains/RealTimeGraphEx/Components/MouseValueToolTip.cs
blob: 115f84b342bc203c928a4f955d3efb1e8ec55ea7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace RealTimeGraphEx.Components
{
    public class MouseValueToolTip : ComponentBase
    {

        /// <summary>
        /// Gets or sets the tool tip template.
        /// </summary>
        /// <value>
        /// The tool tip template.
        /// </value>
        public DataTemplate ToolTipTemplate
        {
            get { return (DataTemplate)GetValue(ToolTipTemplateProperty); }
            set { SetValue(ToolTipTemplateProperty, value); }
        }
        public static readonly DependencyProperty ToolTipTemplateProperty =
            DependencyProperty.Register("ToolTipTemplate", typeof(DataTemplate), typeof(MouseValueToolTip), new PropertyMetadata(null));


        public override void Render(RealTimeGraphExBase graph, bool animate = false)
        {
            graph.gridInnerContentWrapper.Children.Remove(this);
            graph.gridInnerContentWrapper.Children.Add(this);

            if (ToolTipTemplate != null)
            {
                this.ContentTemplate = ToolTipTemplate;
            }

            this.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            this.VerticalAlignment = System.Windows.VerticalAlignment.Top;
            this.Visibility = System.Windows.Visibility.Hidden;
            graph.MouseMove += graph_MouseMove;
            graph.MouseLeave += graph_MouseLeave;
        }

        private void graph_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
        {
            this.Visibility = System.Windows.Visibility.Hidden;
        }

        private void graph_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
        {
            this.Visibility = System.Windows.Visibility.Visible;

            double x = e.GetPosition(Graph.gridInnerContentWrapper).X;
            double y = e.GetPosition(Graph.gridInnerContentWrapper).Y;

            if (y > Graph.gridInnerContentWrapper.ActualHeight / 2)
            {
                y -= this.ActualHeight + 1;
            }
            if (x > Graph.gridInnerContentWrapper.ActualWidth / 2)
            {
                x -= this.ActualWidth  + 1;
            }

            this.Margin = new System.Windows.Thickness(x, y, 0, 0);
            this.Content = Graph.MouseValue;
        }
    }
}