|
1 | 1 | using System.Windows.Media;
|
2 | 2 | using System.Windows.Media.Animation;
|
| 3 | +using System.Windows.Threading; |
3 | 4 |
|
4 | 5 | namespace MaterialDesignThemes.Wpf;
|
5 | 6 |
|
@@ -60,19 +61,36 @@ private static void MouseButtonEventHandler(object sender, MouseButtonEventArgs
|
60 | 61 |
|
61 | 62 | private static void MouseMoveEventHandler(object sender, MouseEventArgs e)
|
62 | 63 | {
|
63 |
| - foreach (var ripple in PressedInstances.ToList()) |
| 64 | +#if NET6_0_OR_GREATER |
| 65 | + DispatcherExtensions.Invoke(Dispatcher.CurrentDispatcher, () => |
| 66 | + { |
| 67 | + foreach (var ripple in PressedInstances.ToList()) |
| 68 | + { |
| 69 | + var relativePosition = Mouse.GetPosition(ripple); |
| 70 | + if (relativePosition.X < 0 || relativePosition.Y < 0 || relativePosition.X >= ripple.ActualWidth || relativePosition.Y >= ripple.ActualHeight) |
| 71 | + { |
| 72 | + VisualStateManager.GoToState(ripple, TemplateStateMouseOut, true); |
| 73 | + PressedInstances.Remove(ripple); |
| 74 | + } |
| 75 | + } |
| 76 | + }); |
| 77 | +#else |
| 78 | + if (Dispatcher.CurrentDispatcher.CheckAccess()) |
64 | 79 | {
|
65 |
| - var relativePosition = Mouse.GetPosition(ripple); |
66 |
| - if (relativePosition.X < 0 |
67 |
| - || relativePosition.Y < 0 |
68 |
| - || relativePosition.X >= ripple.ActualWidth |
69 |
| - || relativePosition.Y >= ripple.ActualHeight) |
70 |
| - |
71 |
| - { |
72 |
| - VisualStateManager.GoToState(ripple, TemplateStateMouseOut, true); |
73 |
| - PressedInstances.Remove(ripple); |
74 |
| - } |
| 80 | + Dispatcher.CurrentDispatcher.Invoke(() => |
| 81 | + { |
| 82 | + foreach (var ripple in PressedInstances.ToList()) |
| 83 | + { |
| 84 | + var relativePosition = Mouse.GetPosition(ripple); |
| 85 | + if (relativePosition.X < 0 || relativePosition.Y < 0 || relativePosition.X >= ripple.ActualWidth || relativePosition.Y >= ripple.ActualHeight) |
| 86 | + { |
| 87 | + VisualStateManager.GoToState(ripple, TemplateStateMouseOut, true); |
| 88 | + PressedInstances.Remove(ripple); |
| 89 | + } |
| 90 | + } |
| 91 | + }); |
75 | 92 | }
|
| 93 | +#endif |
76 | 94 | }
|
77 | 95 |
|
78 | 96 | public static readonly DependencyProperty FeedbackProperty = DependencyProperty.Register(
|
|
0 commit comments