mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
UI - Large amount of memory improvements in the VMs
Core - Minor memory improvements
This commit is contained in:
1 parent
8d5ab86d11
commit
b9dff33236
26 files changed
+243
-191
No files matched your search
@@ -1,9 +1,15 @@
|
||||
using System.Windows;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace Artemis.UI.Behaviors
|
||||
{
|
||||
public class InputBindingBehavior
|
||||
{
|
||||
private static List<Tuple<FrameworkElement, Window, InputBinding>> _movedInputBindings = new List<Tuple<FrameworkElement, Window, InputBinding>>();
|
||||
|
||||
public static readonly DependencyProperty PropagateInputBindingsToWindowProperty =
|
||||
DependencyProperty.RegisterAttached("PropagateInputBindingsToWindow", typeof(bool), typeof(InputBindingBehavior),
|
||||
new PropertyMetadata(false, OnPropagateInputBindingsToWindowChanged));
|
||||
@@ -21,13 +27,13 @@ namespace Artemis.UI.Behaviors
|
||||
private static void OnPropagateInputBindingsToWindowChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
((FrameworkElement) d).Loaded += OnLoaded;
|
||||
((FrameworkElement) d).Unloaded += OnUnloaded;
|
||||
}
|
||||
|
||||
private static void OnLoaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var frameworkElement = (FrameworkElement) sender;
|
||||
frameworkElement.Loaded -= OnLoaded;
|
||||
|
||||
|
||||
var window = Window.GetWindow(frameworkElement);
|
||||
if (window == null) return;
|
||||
|
||||
@@ -37,7 +43,23 @@ namespace Artemis.UI.Behaviors
|
||||
var inputBinding = frameworkElement.InputBindings[i];
|
||||
window.InputBindings.Add(inputBinding);
|
||||
frameworkElement.InputBindings.Remove(inputBinding);
|
||||
|
||||
_movedInputBindings.Add(new Tuple<FrameworkElement, Window, InputBinding>(frameworkElement, window, inputBinding));
|
||||
}
|
||||
}
|
||||
|
||||
private static void OnUnloaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var frameworkElement = (FrameworkElement) sender;
|
||||
|
||||
var toRemove = _movedInputBindings.Where(m => m.Item1 == frameworkElement).ToList();
|
||||
foreach (var (_, window, inputBinding) in toRemove)
|
||||
{
|
||||
if (window.InputBindings.Contains(inputBinding))
|
||||
window.InputBindings.Remove(inputBinding);
|
||||
}
|
||||
|
||||
_movedInputBindings = _movedInputBindings.Where(b => b.Item1 != frameworkElement).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user