using RealTimeGraphX.EventArguments;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
namespace RealTimeGraphX.WPF
{
///
/// Represents a graph component base class.
///
///
public abstract class WpfGraphComponentBase : Control
{
///
/// Gets or sets the graph controller.
///
public IGraphController Controller
{
get { return (IGraphController)GetValue(ControllerProperty); }
set { SetValue(ControllerProperty, value); }
}
public static readonly DependencyProperty ControllerProperty =
DependencyProperty.Register("Controller", typeof(IGraphController), typeof(WpfGraphComponentBase), new PropertyMetadata(null, (d, e) => (d as WpfGraphComponentBase).OnControllerChanged(e.OldValue as IGraphController, e.NewValue as IGraphController)));
///
/// Called when the controller has changed.
///
/// The old controller.
/// The new controller.
protected virtual void OnControllerChanged(IGraphController oldController, IGraphController newController)
{
if (oldController != null)
{
oldController.VirtualRangeChanged -= OnVirtualRangeChanged;
}
if (newController != null)
{
newController.VirtualRangeChanged += OnVirtualRangeChanged;
}
}
///
/// Handles the event.
///
/// The source of the event.
/// The event arguments.
protected virtual void OnVirtualRangeChanged(object sender, RangeChangedEventArgs e)
{
//Optional
}
///
/// Invokes the specified method on the component dispatcher.
///
/// The action.
protected void InvokeUI(Action action)
{
Dispatcher.BeginInvoke(action);
}
}
}