diff --git a/src/Artemis.UI.Shared/Controls/DeviceVisualizer.cs b/src/Artemis.UI.Shared/Controls/DeviceVisualizer.cs index 1a60ac398..2628c84fb 100644 --- a/src/Artemis.UI.Shared/Controls/DeviceVisualizer.cs +++ b/src/Artemis.UI.Shared/Controls/DeviceVisualizer.cs @@ -3,12 +3,13 @@ using System.Collections.Generic; using System.ComponentModel; using System.IO; using System.Linq; +using System.Timers; using System.Windows; using System.Windows.Controls; using System.Windows.Media; using System.Windows.Media.Imaging; -using System.Windows.Threading; using Artemis.Core; +using Stylet; namespace Artemis.UI.Shared { @@ -37,7 +38,7 @@ namespace Artemis.UI.Shared private readonly DrawingGroup _backingStore; private readonly List _deviceVisualizerLeds; - private readonly DispatcherTimer _timer; + private readonly Timer _timer; private BitmapImage? _deviceImage; private ArtemisDevice? _oldDevice; @@ -50,8 +51,8 @@ namespace Artemis.UI.Shared _deviceVisualizerLeds = new List(); // Run an update timer at 25 fps - _timer = new DispatcherTimer {Interval = TimeSpan.FromMilliseconds(40)}; - _timer.Tick += TimerOnTick; + _timer = new Timer(40); + _timer.Elapsed += TimerOnTick; Loaded += OnLoaded; Unloaded += OnUnloaded; @@ -93,17 +94,7 @@ namespace Artemis.UI.Shared /// protected virtual void Dispose(bool disposing) { - if (disposing) - { - _timer.Stop(); - } - } - - /// - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); + if (disposing) _timer.Stop(); } /// @@ -190,7 +181,7 @@ namespace Artemis.UI.Shared if (_oldDevice != null) { - if (Device != null) + if (Device != null) Device.RgbDevice.PropertyChanged -= DevicePropertyChanged; _oldDevice = null; } @@ -203,8 +194,11 @@ namespace Artemis.UI.Shared private void TimerOnTick(object? sender, EventArgs e) { - if (ShowColors && Visibility == Visibility.Visible) - Render(); + Execute.PostToUIThread(() => + { + if (ShowColors && Visibility == Visibility.Visible) + Render(); + }); } private void UpdateTransform() @@ -295,17 +289,20 @@ namespace Artemis.UI.Shared DrawingContext drawingContext = _backingStore.Open(); if (HighlightedLeds != null && HighlightedLeds.Any()) - { foreach (DeviceVisualizerLed deviceVisualizerLed in _deviceVisualizerLeds) deviceVisualizerLed.RenderColor(drawingContext, !HighlightedLeds.Contains(deviceVisualizerLed.Led)); - } else - { foreach (DeviceVisualizerLed deviceVisualizerLed in _deviceVisualizerLeds) deviceVisualizerLed.RenderColor(drawingContext, false); - } drawingContext.Close(); } + + /// + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } } } \ No newline at end of file diff --git a/src/Artemis.UI/Screens/ProfileEditor/ProfileTree/ProfileTreeViewModel.cs b/src/Artemis.UI/Screens/ProfileEditor/ProfileTree/ProfileTreeViewModel.cs index 15b3f486f..ee754e491 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/ProfileTree/ProfileTreeViewModel.cs +++ b/src/Artemis.UI/Screens/ProfileEditor/ProfileTree/ProfileTreeViewModel.cs @@ -2,7 +2,6 @@ using System.Linq; using System.Windows; using Artemis.Core; -using Artemis.Storage.Entities.Profile; using Artemis.UI.Ninject.Factories; using Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem; using Artemis.UI.Shared; @@ -74,8 +73,8 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree private static DragDropType GetDragDropType(IDropInfo dropInfo) { - TreeItemViewModel source = (TreeItemViewModel)dropInfo.Data; - TreeItemViewModel target = (TreeItemViewModel)dropInfo.TargetItem; + if (!(dropInfo.Data is TreeItemViewModel source) || !(dropInfo.TargetItem is TreeItemViewModel target)) + return DragDropType.None; if (source == target) return DragDropType.None; @@ -121,14 +120,16 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree public void Drop(IDropInfo dropInfo) { - TreeItemViewModel source = (TreeItemViewModel)dropInfo.Data; - TreeItemViewModel target = (TreeItemViewModel)dropInfo.TargetItem; + if (!(dropInfo.Data is TreeItemViewModel source) || !(dropInfo.TargetItem is TreeItemViewModel target)) + return; + if (source == target) + return; DragDropType dragDropType = GetDragDropType(dropInfo); switch (dragDropType) { case DragDropType.Add: - ((TreeItemViewModel)source.Parent).RemoveExistingElement(source); + ((TreeItemViewModel) source.Parent).RemoveExistingElement(source); target.AddExistingElement(source); break; case DragDropType.InsertBefore: diff --git a/src/Artemis.UI/Screens/Settings/Tabs/Modules/ModuleOrderTabViewModel.cs b/src/Artemis.UI/Screens/Settings/Tabs/Modules/ModuleOrderTabViewModel.cs index 89c1335ec..5ba0b72e4 100644 --- a/src/Artemis.UI/Screens/Settings/Tabs/Modules/ModuleOrderTabViewModel.cs +++ b/src/Artemis.UI/Screens/Settings/Tabs/Modules/ModuleOrderTabViewModel.cs @@ -53,8 +53,11 @@ namespace Artemis.UI.Screens.Settings.Tabs.Modules if (dropInfo.TargetItem == dropInfo.Data) return; - ModuleOrderModuleViewModel viewModel = (ModuleOrderModuleViewModel) dropInfo.Data; - BindableCollection targetCollection = (BindableCollection) dropInfo.TargetCollection; + if (!(dropInfo.Data is ModuleOrderModuleViewModel viewModel)) + return; + if (!(dropInfo.TargetCollection is BindableCollection targetCollection)) + return; + int insertIndex = dropInfo.InsertIndex; ModulePriorityCategory category;