-
Notifications
You must be signed in to change notification settings - Fork 115
/
UIElement_Events.cs
1031 lines (884 loc) · 33.1 KB
/
UIElement_Events.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*===================================================================================
*
* Copyright (c) Userware/OpenSilver.net
*
* This file is part of the OpenSilver Runtime (https://opensilver.net), which is
* licensed under the MIT license: https://opensource.org/licenses/MIT
*
* As stated in the MIT license, "the above copyright notice and this permission
* notice shall be included in all copies or substantial portions of the Software."
*
\*====================================================================================*/
using System;
using System.Collections.Generic;
using CSHTML5.Internal;
using OpenSilver.Internal;
#if MIGRATION
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading;
#else
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.System;
#endif
#if MIGRATION
namespace System.Windows
#else
namespace Windows.UI.Xaml
#endif
{
partial class UIElement
{
internal const int MAX_ELEMENTS_IN_ROUTE = 4096;
private EventHandlersStore _eventHandlersStore;
private void EnsureEventHandlersStore()
{
if (_eventHandlersStore == null)
{
_eventHandlersStore = new EventHandlersStore();
}
}
#if MIGRATION
private static void RegisterEvents(Type type)
{
RoutedEvent.RegisterClassHandler(MouseMoveEvent, new MouseEventHandler(OnMouseMoveThunk));
RoutedEvent.RegisterClassHandler(MouseLeftButtonDownEvent, new MouseButtonEventHandler(OnMouseLeftButtonDownThunk));
RoutedEvent.RegisterClassHandler(MouseRightButtonDownEvent, new MouseButtonEventHandler(OnMouseRightButtonDownThunk));
RoutedEvent.RegisterClassHandler(MouseWheelEvent, new MouseWheelEventHandler(OnMouseWheelThunk));
RoutedEvent.RegisterClassHandler(MouseLeftButtonUpEvent, new MouseButtonEventHandler(OnMouseLeftButtonUpThunk));
RoutedEvent.RegisterClassHandler(MouseEnterEvent, new MouseEventHandler(OnMouseEnterThunk));
RoutedEvent.RegisterClassHandler(MouseLeaveEvent, new MouseEventHandler(OnMouseLeaveThunk));
RoutedEvent.RegisterClassHandler(TextInputEvent, new TextCompositionEventHandler(OnTextInputThunk));
RoutedEvent.RegisterClassHandler(TappedEvent, new TappedEventHandler(OnTappedThunk));
RoutedEvent.RegisterClassHandler(MouseRightButtonUpEvent, new MouseButtonEventHandler(OnMouseRightButtonUpThunk));
RoutedEvent.RegisterClassHandler(KeyDownEvent, new KeyEventHandler(OnKeyDownThunk));
RoutedEvent.RegisterClassHandler(KeyUpEvent, new KeyEventHandler(OnKeyUpThunk));
RoutedEvent.RegisterClassHandler(GotFocusEvent, new RoutedEventHandler(OnGotFocusThunk));
RoutedEvent.RegisterClassHandler(LostFocusEvent, new RoutedEventHandler(OnLostFocusThunk));
}
private static void OnMouseMoveThunk(object sender, MouseEventArgs e) => ((UIElement)sender).OnMouseMove(e);
private static void OnMouseLeftButtonDownThunk(object sender, MouseButtonEventArgs e) => ((UIElement)sender).OnMouseLeftButtonDown(e);
private static void OnMouseRightButtonDownThunk(object sender, MouseButtonEventArgs e) => ((UIElement)sender).OnMouseRightButtonDown(e);
private static void OnMouseWheelThunk(object sender, MouseWheelEventArgs e) => ((UIElement)sender).OnMouseWheel(e);
private static void OnMouseLeftButtonUpThunk(object sender, MouseButtonEventArgs e) => ((UIElement)sender).OnMouseLeftButtonUp(e);
private static void OnMouseEnterThunk(object sender, MouseEventArgs e) => ((UIElement)sender).OnMouseEnter(e);
private static void OnMouseLeaveThunk(object sender, MouseEventArgs e) => ((UIElement)sender).OnMouseLeave(e);
private static void OnTextInputThunk(object sender, TextCompositionEventArgs e) => ((UIElement)sender).OnTextInput(e);
private static void OnTappedThunk(object sender, TappedRoutedEventArgs e) => ((UIElement)sender).OnTapped(e);
private static void OnMouseRightButtonUpThunk(object sender, MouseButtonEventArgs e) => ((UIElement)sender).OnMouseRightButtonUp(e);
private static void OnKeyDownThunk(object sender, KeyEventArgs e) => ((UIElement)sender).OnKeyDown(e);
private static void OnKeyUpThunk(object sender, KeyEventArgs e) => ((UIElement)sender).OnKeyUp(e);
private static void OnGotFocusThunk(object sender, RoutedEventArgs e) => ((UIElement)sender).OnGotFocus(e);
private static void OnLostFocusThunk(object sender, RoutedEventArgs e) => ((UIElement)sender).OnLostFocus(e);
#else
private static void RegisterEvents(Type type)
{
RoutedEvent.RegisterClassHandler(PointerMovedEvent, new PointerEventHandler(OnMouseMoveThunk));
RoutedEvent.RegisterClassHandler(PointerPressedEvent, new PointerEventHandler(OnMouseLeftButtonDownThunk));
RoutedEvent.RegisterClassHandler(PointerWheelChangedEvent, new PointerEventHandler(OnMouseWheelThunk));
RoutedEvent.RegisterClassHandler(PointerReleasedEvent, new PointerEventHandler(OnMouseLeftButtonUpThunk));
RoutedEvent.RegisterClassHandler(PointerEnteredEvent, new PointerEventHandler(OnMouseEnterThunk));
RoutedEvent.RegisterClassHandler(PointerExitedEvent, new PointerEventHandler(OnMouseLeaveThunk));
RoutedEvent.RegisterClassHandler(TextInputEvent, new TextCompositionEventHandler(OnTextInputThunk));
RoutedEvent.RegisterClassHandler(TappedEvent, new TappedEventHandler(OnTappedThunk));
RoutedEvent.RegisterClassHandler(RightTappedEvent, new RightTappedEventHandler(OnMouseRightButtonUpThunk));
RoutedEvent.RegisterClassHandler(KeyDownEvent, new KeyEventHandler(OnKeyDownThunk));
RoutedEvent.RegisterClassHandler(KeyUpEvent, new KeyEventHandler(OnKeyUpThunk));
RoutedEvent.RegisterClassHandler(GotFocusEvent, new RoutedEventHandler(OnGotFocusThunk));
RoutedEvent.RegisterClassHandler(LostFocusEvent, new RoutedEventHandler(OnLostFocusThunk));
}
private static void OnMouseMoveThunk(object sender, PointerRoutedEventArgs e) => ((UIElement)sender).OnPointerMoved(e);
private static void OnMouseLeftButtonDownThunk(object sender, PointerRoutedEventArgs e) => ((UIElement)sender).OnPointerPressed(e);
private static void OnMouseWheelThunk(object sender, PointerRoutedEventArgs e) => ((UIElement)sender).OnPointerWheelChanged(e);
private static void OnMouseLeftButtonUpThunk(object sender, PointerRoutedEventArgs e) => ((UIElement)sender).OnPointerReleased(e);
private static void OnMouseEnterThunk(object sender, PointerRoutedEventArgs e) => ((UIElement)sender).OnPointerEntered(e);
private static void OnMouseLeaveThunk(object sender, PointerRoutedEventArgs e) => ((UIElement)sender).OnPointerExited(e);
private static void OnTextInputThunk(object sender, TextCompositionEventArgs e) => ((UIElement)sender).OnTextInput(e);
private static void OnTappedThunk(object sender, TappedRoutedEventArgs e) => ((UIElement)sender).OnTapped(e);
private static void OnMouseRightButtonUpThunk(object sender, RightTappedRoutedEventArgs e) => ((UIElement)sender).OnRightTapped(e);
private static void OnKeyDownThunk(object sender, KeyRoutedEventArgs e) => ((UIElement)sender).OnKeyDown(e);
private static void OnKeyUpThunk(object sender, KeyRoutedEventArgs e) => ((UIElement)sender).OnKeyUp(e);
private static void OnGotFocusThunk(object sender, RoutedEventArgs e) => ((UIElement)sender).OnGotFocus(e);
private static void OnLostFocusThunk(object sender, RoutedEventArgs e) => ((UIElement)sender).OnLostFocus(e);
#endif
/// <summary>
/// Adds a routed event handler for a specified routed event, adding the handler
/// to the handler collection on the current element. Specify handledEventsToo as
/// true to have the provided handler be invoked for routed event that had already
/// been marked as handled by another element along the event route.
/// </summary>
/// <param name="routedEvent">
/// An identifier for the routed event to be handled.
/// </param>
/// <param name="handler">
/// A reference to the handler implementation.
/// </param>
/// <param name="handledEventsToo">
/// true to register the handler such that it is invoked even when the routed event
/// is marked handled in its event data; false to register the handler with the default
/// condition that it will not be invoked if the routed event is already marked handled.
/// The default is false. Do not routinely ask to rehandle a routed event. For more
/// information, see Remarks.
/// </param>
/// <exception cref="ArgumentNullException">
/// routedEvent or handler is null.
/// </exception>
/// <exception cref="ArgumentException">
/// routedEvent does not represent a supported routed event.-or-handler does not
/// implement a supported delegate.
/// </exception>
/// <exception cref="NotImplementedException">
/// Attempted to add handler for an event not supported by the current platform variation.
/// </exception>
public void AddHandler(RoutedEvent routedEvent, Delegate handler, bool handledEventsToo)
{
if (routedEvent == null)
{
throw new ArgumentNullException(nameof(routedEvent));
}
if (handler == null)
{
throw new ArgumentNullException(nameof(handler));
}
if (!routedEvent.IsLegalHandler(handler))
{
throw new ArgumentException("Handler type is mismatched.");
}
EnsureEventHandlersStore();
_eventHandlersStore.AddRoutedEventHandler(routedEvent, handler, handledEventsToo);
}
/// <summary>
/// Removes the specified routed event handler from this <see cref="UIElement"/>.
/// </summary>
/// <param name="routedEvent">
/// The identifier of the routed event for which the handler is attached.
/// </param>
/// <param name="handler">
/// The specific handler implementation to remove from the event handler collection
/// on this <see cref="UIElement"/>.
/// </param>
/// <exception cref="ArgumentNullException">
/// routedEvent or handler is null.
/// </exception>
/// <exception cref="ArgumentException">
/// routedEvent does not represent a supported routed event.-or-handler does not
/// implement a supported delegate.
/// </exception>
/// <exception cref="NotImplementedException">
/// Attempted to remove handler for an event not supported by the current platform
/// variation.
/// </exception>
public void RemoveHandler(RoutedEvent routedEvent, Delegate handler)
{
if (routedEvent == null)
{
throw new ArgumentNullException(nameof(routedEvent));
}
if (handler == null)
{
throw new ArgumentNullException(nameof(handler));
}
if (!routedEvent.IsLegalHandler(handler))
{
throw new ArgumentException("Handler type is mismatched.");
}
EventHandlersStore store = _eventHandlersStore;
if (store != null)
{
store.RemoveRoutedEventHandler(routedEvent, handler);
}
}
/// <summary>
/// Raise the events specified by
/// <see cref="RoutedEventArgs.RoutedEvent"/>
/// </summary>
internal void RaiseEvent(RoutedEventArgs e)
{
if (e == null)
{
throw new ArgumentNullException(nameof(e));
}
if (e.OriginalSource == null)
{
e.OriginalSource = this;
}
EventRoute route = new EventRoute(e.RoutedEvent);
BuildRouteHelper(this, route, e);
route.InvokeHandlers(e);
}
internal static void BuildRouteHelper(DependencyObject e, EventRoute route, RoutedEventArgs args)
{
if (route == null)
{
throw new ArgumentNullException(nameof(route));
}
if (args == null)
{
throw new ArgumentNullException(nameof(args));
}
if (args.RoutedEvent != route.RoutedEvent)
{
throw new ArgumentException("RoutedEvent in RoutedEventArgs and EventRoute are mismatched.");
}
if (args.RoutedEvent.RoutingStrategy == RoutingStrategy.Direct)
{
UIElement uiElement = e as UIElement;
// Add this element to route
if (uiElement != null)
{
uiElement.AddToEventRoute(route, args);
}
}
else
{
int cElements = 0;
while (e != null)
{
UIElement uiElement = e as UIElement;
// Protect against infinite loops by limiting the number of elements
// that we will process.
if (cElements++ > MAX_ELEMENTS_IN_ROUTE)
{
throw new InvalidOperationException("Potential cycle in tree found while building the event route.");
}
// Invoke BuildRouteCore
if (uiElement != null)
{
// Add this element to route
uiElement.AddToEventRoute(route, args);
// Get element's visual parent
e = VisualTreeHelper.GetParent(uiElement);
}
}
}
}
/// <summary>
/// Add the event handlers for this element to the route.
/// </summary>
internal void AddToEventRoute(EventRoute route, RoutedEventArgs e)
{
if (route == null)
{
throw new ArgumentNullException(nameof(route));
}
if (e == null)
{
throw new ArgumentNullException(nameof(e));
}
route.Add(this, RoutedEvent.GetClassHandler(e.RoutedEvent), false);
EventHandlersStore store = _eventHandlersStore;
if (store != null)
{
List<RoutedEventHandlerInfo> instanceListeners = store[e.RoutedEvent];
// Add all instance listeners for this UIElement
if (instanceListeners != null)
{
for (int i = 0; i < instanceListeners.Count; i++)
{
route.Add(this, instanceListeners[i].Handler, instanceListeners[i].InvokeHandledEventsToo);
}
}
}
}
#region Pointer moved event
#if MIGRATION
public static readonly RoutedEvent MouseMoveEvent;
#else
public static readonly RoutedEvent PointerMovedEvent;
#endif
/// <summary>
/// Occurs when the pointer device that previously initiated a Press action is
/// moved, while within this element.
/// </summary>
#if MIGRATION
public event MouseEventHandler MouseMove
{
add
{
AddHandler(MouseMoveEvent, value, false);
}
remove
{
RemoveHandler(MouseMoveEvent, value);
}
}
#else
public event PointerEventHandler PointerMoved
{
add
{
AddHandler(PointerMovedEvent, value, false);
}
remove
{
RemoveHandler(PointerMovedEvent, value);
}
}
#endif
/// <summary>
/// Raises the PointerMoved event
/// </summary>
/// <param name="eventArgs">The arguments for the event.</param>
#if MIGRATION
protected virtual void OnMouseMove(MouseEventArgs eventArgs)
{
}
#else
protected virtual void OnPointerMoved(PointerRoutedEventArgs eventArgs)
{
}
#endif
#endregion
#region Pointer pressed event
#if MIGRATION
public static readonly RoutedEvent MouseLeftButtonDownEvent;
#else
public static readonly RoutedEvent PointerPressedEvent;
#endif
/// <summary>
/// Occurs when the pointer device that previously initiated a Press action is
/// pressed, while within this element.
/// </summary>
#if MIGRATION
public event MouseButtonEventHandler MouseLeftButtonDown
{
add
{
AddHandler(MouseLeftButtonDownEvent, value, false);
}
remove
{
RemoveHandler(MouseLeftButtonDownEvent, value);
}
}
#else
public event PointerEventHandler PointerPressed
{
add
{
AddHandler(PointerPressedEvent, value, false);
}
remove
{
RemoveHandler(PointerPressedEvent, value);
}
}
#endif
/// <summary>
/// Raises the PointerPressed event
/// </summary>
/// <param name="eventArgs">The arguments for the event.</param>
#if MIGRATION
protected virtual void OnMouseLeftButtonDown(MouseButtonEventArgs eventArgs)
{
}
#else
protected virtual void OnPointerPressed(PointerRoutedEventArgs eventArgs)
{
}
#endif
#endregion
#region MouseRightButtonDown (no equivalent in UWP)
#if MIGRATION
/// <summary>
/// Identifies the <see cref="MouseRightButtonDown"/> routed event.
/// </summary>
public static readonly RoutedEvent MouseRightButtonDownEvent;
public event MouseButtonEventHandler MouseRightButtonDown
{
add
{
AddHandler(MouseRightButtonDownEvent, value, false);
}
remove
{
RemoveHandler(MouseRightButtonDownEvent, value);
}
}
/// <summary>
/// Raises the MouseRightButtonDown event
/// </summary>
/// <param name="eventArgs">The arguments for the event.</param>
protected virtual void OnMouseRightButtonDown(MouseButtonEventArgs eventArgs)
{
}
#endif
#endregion
#region PointerWheelChanged event (or MouseWheel)
#if MIGRATION
/// <summary>
/// Identifies the <see cref="MouseWheel"/> routed event.
/// </summary>
public static readonly RoutedEvent MouseWheelEvent;
#else
/// <summary>
/// Identifies the <see cref="PointerWheelChanged"/> routed event.
/// </summary>
public static readonly RoutedEvent PointerWheelChangedEvent;
#endif
#if MIGRATION
/// <summary>
/// Occurs when the user rotates the mouse wheel while the mouse pointer is over
/// a <see cref="UIElement"/>, or the <see cref="UIElement"/> has focus.
/// </summary>
public event MouseWheelEventHandler MouseWheel
{
add
{
AddHandler(MouseWheelEvent, value, false);
}
remove
{
RemoveHandler(MouseWheelEvent, value);
}
}
#else
/// <summary>
/// Occurs when the user rotates the mouse wheel while the mouse pointer is over
/// a <see cref="UIElement"/>, or the <see cref="UIElement"/> has focus.
/// </summary>
public event PointerEventHandler PointerWheelChanged
{
add
{
AddHandler(PointerWheelChangedEvent, value, false);
}
remove
{
RemoveHandler(PointerWheelChangedEvent, value);
}
}
#endif
/// <summary>
/// Raises the PointerWheelChanged event
/// </summary>
/// <param name="eventArgs">The arguments for the event.</param>
#if MIGRATION
protected virtual void OnMouseWheel(MouseWheelEventArgs eventArgs)
{
}
#else
protected virtual void OnPointerWheelChanged(PointerRoutedEventArgs eventArgs)
{
}
#endif
#endregion
#region Pointer released event
#if MIGRATION
public static readonly RoutedEvent MouseLeftButtonUpEvent;
#else
public static readonly RoutedEvent PointerReleasedEvent;
#endif
/// <summary>
/// Occurs when the pointer device that previously initiated a Press action is
/// released, while within this element.
/// </summary>
#if MIGRATION
public event MouseButtonEventHandler MouseLeftButtonUp
{
add
{
AddHandler(MouseLeftButtonUpEvent, value, false);
}
remove
{
RemoveHandler(MouseLeftButtonUpEvent, value);
}
}
#else
public event PointerEventHandler PointerReleased
{
add
{
AddHandler(PointerReleasedEvent, value, false);
}
remove
{
RemoveHandler(PointerReleasedEvent, value);
}
}
#endif
/// <summary>
/// Raises the PointerReleased event
/// </summary>
/// <param name="eventArgs">The arguments for the event.</param>
#if MIGRATION
protected virtual void OnMouseLeftButtonUp(MouseButtonEventArgs eventArgs)
{
}
#else
protected virtual void OnPointerReleased(PointerRoutedEventArgs eventArgs)
{
}
#endif
#endregion
#region Pointer entered event
#if MIGRATION
public static readonly RoutedEvent MouseEnterEvent;
#else
public static readonly RoutedEvent PointerEnteredEvent;
#endif
/// <summary>
/// Occurs when a pointer enters the hit test area of this element.
/// </summary>
#if MIGRATION
public event MouseEventHandler MouseEnter
{
add
{
AddHandler(MouseEnterEvent, value, false);
}
remove
{
RemoveHandler(MouseEnterEvent, value);
}
}
#else
public event PointerEventHandler PointerEntered
{
add
{
AddHandler(PointerEnteredEvent, value, false);
}
remove
{
RemoveHandler(PointerEnteredEvent, value);
}
}
#endif
/// <summary>
/// Raises the PointerEntered event
/// </summary>
/// <param name="eventArgs">The arguments for the event.</param>
#if MIGRATION
protected virtual void OnMouseEnter(MouseEventArgs eventArgs)
{
}
#else
protected virtual void OnPointerEntered(PointerRoutedEventArgs eventArgs)
{
}
#endif
#endregion
#region Pointer exited event
#if MIGRATION
public static readonly RoutedEvent MouseLeaveEvent;
#else
public static readonly RoutedEvent PointerExitedEvent;
#endif
/// <summary>
/// Occurs when a pointer leaves the hit test area of this element.
/// </summary>
#if MIGRATION
public event MouseEventHandler MouseLeave
{
add
{
AddHandler(MouseLeaveEvent, value, false);
}
remove
{
RemoveHandler(MouseLeaveEvent, value);
}
}
#else
public event PointerEventHandler PointerExited
{
add
{
AddHandler(PointerExitedEvent, value, false);
}
remove
{
RemoveHandler(PointerExitedEvent, value);
}
}
#endif
/// <summary>
/// Raises the PointerExited event
/// </summary>
/// <param name="eventArgs">The arguments for the event.</param>
#if MIGRATION
protected internal virtual void OnMouseLeave(MouseEventArgs eventArgs)
{
}
#else
protected internal virtual void OnPointerExited(PointerRoutedEventArgs eventArgs)
{
}
#endif
#endregion
#region Text events
/// <summary>
/// Identifies the <see cref="TextInput"/> routed event.
/// </summary>
public static readonly RoutedEvent TextInputEvent;
/// <summary>
/// Occurs when a UI element gets text in a device-independent manner.
/// </summary>
/// <summary>
/// Occurs when a keyboard key is pressed while the UIElement has focus.
/// </summary>
public event TextCompositionEventHandler TextInput
{
add
{
AddHandler(TextInputEvent, value, false);
}
remove
{
RemoveHandler(TextInputEvent, value);
}
}
/// <summary>
/// Raises the TextInput event
/// </summary>
/// <param name="eventArgs">The arguments for the event.</param>
protected virtual void OnTextInput(TextCompositionEventArgs eventArgs)
{
}
/// <summary>
/// Identifies the <see cref="TextInputStart"/> routed event.
/// </summary>
[OpenSilver.NotImplemented]
public static readonly RoutedEvent TextInputStartEvent;
/// <summary>
/// Identifies the <see cref="TextInputUpdate"/> routed event.
/// </summary>
[OpenSilver.NotImplemented]
public static readonly RoutedEvent TextInputUpdateEvent;
/// <summary>
/// Occurs when a UI element initially gets text in a device-independent manner.
/// </summary>
[OpenSilver.NotImplemented]
public event TextCompositionEventHandler TextInputStart;
/// <summary>
/// Occurs when text continues to be composed via an input method editor (IME).
/// </summary>
[OpenSilver.NotImplemented]
public event TextCompositionEventHandler TextInputUpdate;
#endregion
#region Tapped event
public static readonly RoutedEvent TappedEvent;
/// <summary>
/// Occurs when an otherwise unhandled Tap interaction occurs over the hit test
/// area of this element.
/// </summary>
public event TappedEventHandler Tapped
{
add
{
AddHandler(TappedEvent, value, false);
}
remove
{
RemoveHandler(TappedEvent, value);
}
}
/// <summary>
/// Raises the Tapped event
/// </summary>
/// <param name="eventArgs">The arguments for the event.</param>
protected virtual void OnTapped(TappedRoutedEventArgs eventArgs)
{
}
#endregion
#region RightTapped (aka MouseRightButtonUp) event
#if MIGRATION
public static readonly RoutedEvent MouseRightButtonUpEvent;
#else
public static readonly RoutedEvent RightTappedEvent;
#endif
/// <summary>
/// Occurs when a right-tap input stimulus happens while the pointer is over
/// the element.
/// </summary>
#if MIGRATION
public event MouseButtonEventHandler MouseRightButtonUp
{
add
{
AddHandler(MouseRightButtonUpEvent, value, false);
}
remove
{
RemoveHandler(MouseRightButtonUpEvent, value);
}
}
#else
public event RightTappedEventHandler RightTapped
{
add
{
AddHandler(RightTappedEvent, value, false);
}
remove
{
RemoveHandler(RightTappedEvent, value);
}
}
#endif
/// <summary>
/// Raises the RightTapped event
/// </summary>
/// <param name="eventArgs">The arguments for the event.</param>
#if MIGRATION
protected virtual void OnMouseRightButtonUp(MouseButtonEventArgs eventArgs)
{
}
#else
protected virtual void OnRightTapped(RightTappedRoutedEventArgs eventArgs)
{
}
#endif
#endregion
#region KeyDown event
public static readonly RoutedEvent KeyDownEvent;
/// <summary>
/// Occurs when a keyboard key is pressed while the UIElement has focus.
/// </summary>
public event KeyEventHandler KeyDown
{
add
{
AddHandler(KeyDownEvent, value, false);
}
remove
{
RemoveHandler(KeyDownEvent, value);
}
}
/// <summary>
/// Raises the KeyDown event
/// </summary>
/// <param name="eventArgs">The arguments for the event.</param>
#if MIGRATION
protected virtual void OnKeyDown(KeyEventArgs eventArgs)
{
}
#else
protected virtual void OnKeyDown(KeyRoutedEventArgs eventArgs)
{
}
#endif
#endregion
#region KeyUp event
public static readonly RoutedEvent KeyUpEvent;
/// <summary>
/// Occurs when a keyboard key is released while the UIElement has focus.
/// </summary>
public event KeyEventHandler KeyUp
{
add
{
AddHandler(KeyUpEvent, value, false);
}
remove
{
RemoveHandler(KeyUpEvent, value);
}
}
/// <summary>
/// Raises the KeyUp event
/// </summary>
/// <param name="eventArgs">The arguments for the event.</param>
#if MIGRATION
protected virtual void OnKeyUp(KeyEventArgs eventArgs)
{
}
#else
protected virtual void OnKeyUp(KeyRoutedEventArgs eventArgs)
{
}
#endif
#endregion
#region GotFocus event
public static readonly RoutedEvent GotFocusEvent;
/// <summary>
/// Occurs when the pointer device that previously initiated a Press action is
/// pressed, while within this element.
/// Note that ONLY sender's informations are currently filled (not pointer's)
/// </summary>
public event RoutedEventHandler GotFocus //todo: fill everything and remove the note above
{
add
{
AddHandler(GotFocusEvent, value, false);
}
remove
{
RemoveHandler(GotFocusEvent, value);
}
}
/// <summary>
/// Raises the GotFocus event
/// </summary>
/// <param name="eventArgs">The arguments for the event.</param>
protected virtual void OnGotFocus(RoutedEventArgs eventArgs)
{
}
#endregion
#region Lostfocus event
public static readonly RoutedEvent LostFocusEvent;
/// <summary>
/// Occurs when a UIElement loses focus.
/// </summary>
public event RoutedEventHandler LostFocus
{
add
{
AddHandler(LostFocusEvent, value, false);
}
remove
{
RemoveHandler(LostFocusEvent, value);
}
}
/// <summary>
/// Raises the LostFocus event
/// </summary>
/// <param name="eventArgs">The arguments for the event.</param>
protected virtual void OnLostFocus(RoutedEventArgs eventArgs)
{
}
#endregion
#region Allow or Prevent Focus events for IsTabStop
internal virtual object GetFocusTarget() => INTERNAL_OuterDomElement;
internal void AllowFocusEvents()
{
object target = GetFocusTarget();
if (target != null)
{
OpenSilver.Interop.ExecuteJavaScript("document.enableFocus($0)", ((INTERNAL_HtmlDomElementReference)target).UniqueIdentifier);
}
}