blob: e48c18678f6c1f327abed47832a9e32d7b93c91a (
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
|
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
{
/// <summary>
/// Represents a graph component base class.
/// </summary>
/// <seealso cref="System.Windows.Controls.Control" />
public abstract class WpfGraphComponentBase : Control
{
/// <summary>
/// Gets or sets the graph controller.
/// </summary>
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)));
/// <summary>
/// Called when the controller has changed.
/// </summary>
/// <param name="oldController">The old controller.</param>
/// <param name="newController">The new controller.</param>
protected virtual void OnControllerChanged(IGraphController oldController, IGraphController newController)
{
if (oldController != null)
{
oldController.VirtualRangeChanged -= OnVirtualRangeChanged;
}
if (newController != null)
{
newController.VirtualRangeChanged += OnVirtualRangeChanged;
}
}
/// <summary>
/// Handles the <see cref="IGraphController.VirtualRangeChanged"/> event.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The event arguments.</param>
protected virtual void OnVirtualRangeChanged(object sender, RangeChangedEventArgs e)
{
//Optional
}
/// <summary>
/// Invokes the specified method on the component dispatcher.
/// </summary>
/// <param name="action">The action.</param>
protected void InvokeUI(Action action)
{
Dispatcher.BeginInvoke(action);
}
}
}
|