-
Notifications
You must be signed in to change notification settings - Fork 207
/
Copy pathFrameworkElementContainer.cs
146 lines (125 loc) · 4.25 KB
/
FrameworkElementContainer.cs
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Animation;
using AlphaTab.Platform;
using AlphaTab.Rendering.Utils;
namespace AlphaTab.Wpf
{
internal class FrameworkElementContainer : IContainer
{
public FrameworkElement Control { get; }
public FrameworkElementContainer(FrameworkElement control)
{
Control = control;
Resize = new DelegatedEventEmitter(
value => { Control.SizeChanged += (sender, args) => value(); },
value => { }
);
MouseDown = new DelegatedEventEmitter<IMouseEventArgs>(
value =>
{
Control.MouseDown += (sender, args) => value(new WpfMouseEventArgs(args));
},
value => { }
);
MouseMove = new DelegatedEventEmitter<IMouseEventArgs>(
value =>
{
Control.MouseMove += (sender, args) => value(new WpfMouseEventArgs(args));
},
value => { }
);
MouseUp = new DelegatedEventEmitter<IMouseEventArgs>(
value =>
{
Control.MouseUp += (sender, args) => value(new WpfMouseEventArgs(args));
},
value => { }
);
}
public double Width
{
get => (float) Control.ActualWidth;
set => Control.Width = value;
}
public double Height
{
get => (float) Control.ActualHeight;
set => Control.Height = value;
}
public bool IsVisible => Control.IsVisible && Control.ActualWidth > 0;
public double ScrollLeft
{
get => Control is ScrollViewer scroll ? (float) scroll.HorizontalOffset : 0;
set
{
if (Control is ScrollViewer scroll)
{
scroll.ScrollToHorizontalOffset(value);
}
}
}
public double ScrollTop
{
get => Control is ScrollViewer scroll ? (float) scroll.VerticalOffset : 0;
set
{
if (Control is ScrollViewer scroll)
{
scroll.ScrollToVerticalOffset(value);
}
}
}
public void AppendChild(IContainer child)
{
if (Control is Panel p)
{
p.Children.Add(((FrameworkElementContainer) child).Control);
}
else if (Control is ScrollViewer s && s.Content is ContentControl sc)
{
sc.Content = ((FrameworkElementContainer) child).Control;
}
else if (Control is ScrollViewer ss && ss.Content is Decorator d)
{
d.Child = ((FrameworkElementContainer) child).Control;
}
else if (Control is ScrollViewer sss && sss.Content is Panel pp)
{
pp.Children.Add(((FrameworkElementContainer) child).Control);
}
else if (Control is ContentControl c)
{
c.Content = ((FrameworkElementContainer) child).Control;
}
}
public void StopAnimation()
{
Control.BeginAnimation(Canvas.LeftProperty, null);
}
public void TransitionToX(double duration, double x)
{
Control.BeginAnimation(Canvas.LeftProperty,
new DoubleAnimation(x, new Duration(TimeSpan.FromMilliseconds(duration))));
}
public void Clear()
{
if (Control is Panel p)
{
p.Children.Clear();
}
}
public void SetBounds(double x, double y, double w, double h)
{
Canvas.SetLeft(Control, x);
Canvas.SetTop(Control, y);
Control.Width = w;
Control.Height = h;
}
public IEventEmitter Resize { get; set; }
public IEventEmitterOfT<IMouseEventArgs> MouseDown { get; set; }
public IEventEmitterOfT<IMouseEventArgs> MouseMove { get; set; }
public IEventEmitterOfT<IMouseEventArgs> MouseUp { get; set; }
}
}