Init commit
This commit is contained in:
13
Infrastructure/EventArgs.cs
Normal file
13
Infrastructure/EventArgs.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
|
||||
namespace StructureHelper
|
||||
{
|
||||
public class EventArgs<T> : EventArgs
|
||||
{
|
||||
public EventArgs(T value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
public T Value { get; private set; }
|
||||
}
|
||||
}
|
||||
25
Infrastructure/EventTriggerBase.cs
Normal file
25
Infrastructure/EventTriggerBase.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using EventTrigger = System.Windows.Interactivity.EventTrigger;
|
||||
|
||||
namespace StructureHelper
|
||||
{
|
||||
public class EventTriggerBase<T> : EventTrigger where T : RoutedEventArgs
|
||||
{
|
||||
readonly Predicate<T> eventTriggerPredicate;
|
||||
|
||||
public EventTriggerBase(Predicate<T> eventTriggerPredicate)
|
||||
{
|
||||
this.eventTriggerPredicate = eventTriggerPredicate;
|
||||
}
|
||||
|
||||
protected override void OnEvent(EventArgs eventArgs)
|
||||
{
|
||||
if (eventArgs is T e && eventTriggerPredicate(e))
|
||||
{
|
||||
base.OnEvent(eventArgs);
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
31
Infrastructure/Extensions/ObservableCollectionExtensions.cs
Normal file
31
Infrastructure/Extensions/ObservableCollectionExtensions.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace StructureHelper
|
||||
{
|
||||
public static class ObservableCollectionExtensions
|
||||
{
|
||||
public static void MoveElementToEnd<T>(this ObservableCollection<T> collection, T element)
|
||||
{
|
||||
var elementCopy = element;
|
||||
collection.Remove(element);
|
||||
collection.Add(elementCopy);
|
||||
}
|
||||
|
||||
public static void MoveElementToBegin<T>(this ObservableCollection<T> collection, T element)
|
||||
{
|
||||
var collectionCopy = new List<T>(collection);
|
||||
collectionCopy.Remove(element);
|
||||
collection.Clear();
|
||||
collection.Add(element);
|
||||
foreach (var collectionElem in collectionCopy)
|
||||
collection.Add(collectionElem);
|
||||
}
|
||||
|
||||
public static void MoveElementToSelectedIndex<T>(this ObservableCollection<T> collection, T element, int index)
|
||||
{
|
||||
collection.Remove(element);
|
||||
collection.Insert(index - 1, element);
|
||||
}
|
||||
}
|
||||
}
|
||||
45
Infrastructure/MouseBehaviour.cs
Normal file
45
Infrastructure/MouseBehaviour.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Interactivity;
|
||||
|
||||
namespace StructureHelper
|
||||
{
|
||||
public class MouseBehaviour : Behavior<Panel>
|
||||
{
|
||||
public static readonly DependencyProperty MouseYProperty = DependencyProperty.Register(
|
||||
"MouseY", typeof(double), typeof(MouseBehaviour), new PropertyMetadata(default(double)));
|
||||
|
||||
public static readonly DependencyProperty MouseXProperty = DependencyProperty.Register(
|
||||
"MouseX", typeof(double), typeof(MouseBehaviour), new PropertyMetadata(default(double)));
|
||||
|
||||
public double MouseY
|
||||
{
|
||||
get => (double)GetValue(MouseYProperty);
|
||||
set => SetValue(MouseYProperty, value);
|
||||
}
|
||||
|
||||
public double MouseX
|
||||
{
|
||||
get => (double)GetValue(MouseXProperty);
|
||||
set => SetValue(MouseXProperty, value);
|
||||
}
|
||||
|
||||
protected override void OnAttached()
|
||||
{
|
||||
AssociatedObject.MouseMove += AssociatedObjectOnMouseMove;
|
||||
}
|
||||
|
||||
protected override void OnDetaching()
|
||||
{
|
||||
AssociatedObject.MouseMove -= AssociatedObjectOnMouseMove;
|
||||
}
|
||||
|
||||
private void AssociatedObjectOnMouseMove(object sender, MouseEventArgs mouseEventArgs)
|
||||
{
|
||||
var pos = mouseEventArgs.GetPosition(AssociatedObject);
|
||||
MouseX = pos.X;
|
||||
MouseY = pos.Y;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace StructureHelper.Infrastructure
|
||||
{
|
||||
public class DoubleClickEventTrigger : EventTriggerBase<MouseButtonEventArgs>
|
||||
{
|
||||
public DoubleClickEventTrigger() : base(args => args.ClickCount == 2) { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace StructureHelper.Infrastructure
|
||||
{
|
||||
public class MouseWheelDownEventTrigger : EventTriggerBase<MouseWheelEventArgs>
|
||||
{
|
||||
public MouseWheelDownEventTrigger() : base(args => args.Delta > 0) { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace StructureHelper.Infrastructure
|
||||
{
|
||||
public class MouseWheelUpEventTrigger : EventTriggerBase<MouseWheelEventArgs>
|
||||
{
|
||||
public MouseWheelUpEventTrigger() : base(args => args.Delta < 0) { }
|
||||
}
|
||||
}
|
||||
9
Infrastructure/NamedList.cs
Normal file
9
Infrastructure/NamedList.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace StructureHelper.Infrastructure
|
||||
{
|
||||
public class NamedList<T> : List<T>
|
||||
{
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
||||
27
Infrastructure/RelayCommand.cs
Normal file
27
Infrastructure/RelayCommand.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace StructureHelper
|
||||
{
|
||||
public class RelayCommand : ICommand
|
||||
{
|
||||
private Action<object> execute;
|
||||
private Func<object, bool> canExecute;
|
||||
|
||||
public event EventHandler CanExecuteChanged
|
||||
{
|
||||
add => CommandManager.RequerySuggested += value;
|
||||
remove => CommandManager.RequerySuggested -= value;
|
||||
}
|
||||
|
||||
public RelayCommand(Action<object> execute, Func<object, bool> canExecute = null)
|
||||
{
|
||||
this.execute = execute;
|
||||
this.canExecute = canExecute;
|
||||
}
|
||||
|
||||
public bool CanExecute(object parameter) => canExecute == null || canExecute(parameter);
|
||||
|
||||
public void Execute(object parameter) => execute(parameter);
|
||||
}
|
||||
}
|
||||
27
Infrastructure/ViewModelBase.cs
Normal file
27
Infrastructure/ViewModelBase.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
using StructureHelper.Annotations;
|
||||
|
||||
namespace StructureHelper.Infrastructure
|
||||
{
|
||||
public class ViewModelBase : INotifyPropertyChanged
|
||||
{
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
[NotifyPropertyChangedInvocator]
|
||||
protected virtual void OnPropertyChanged<T>(T value, T prop, [CallerMemberName] string propertyName = null)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
[NotifyPropertyChangedInvocator]
|
||||
protected virtual void OnPropertyChanged<T>(T value, ref T prop, [CallerMemberName] string propertyName = null)
|
||||
{
|
||||
prop = value;
|
||||
OnPropertyChanged(propertyName);
|
||||
}
|
||||
|
||||
[NotifyPropertyChangedInvocator]
|
||||
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user