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
{
///
/// Gets or sets the tool tip template.
///
///
/// The tool tip template.
///
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;
}
}
}