feat: refactor to simplify null control property and event initialization.
This commit is contained in:
@@ -1,41 +0,0 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
|
||||
namespace Ursa.Common;
|
||||
|
||||
internal static class EventHelper
|
||||
{
|
||||
public static void RegisterClickEvent(EventHandler<RoutedEventArgs> handler, params Button?[] buttons)
|
||||
{
|
||||
foreach (var button in buttons)
|
||||
{
|
||||
if(button is not null) button.Click += handler;
|
||||
}
|
||||
}
|
||||
|
||||
public static void UnregisterClickEvent(EventHandler<RoutedEventArgs> handler, params Button?[] buttons)
|
||||
{
|
||||
foreach (var button in buttons)
|
||||
{
|
||||
if(button is not null) button.Click -= handler;
|
||||
}
|
||||
}
|
||||
|
||||
public static void RegisterEvent<TArgs>(RoutedEvent<TArgs> routedEvent, EventHandler<TArgs> handler, params Button?[] controls)
|
||||
where TArgs : RoutedEventArgs
|
||||
{
|
||||
foreach (var control in controls)
|
||||
{
|
||||
control?.AddHandler(routedEvent, handler);
|
||||
}
|
||||
}
|
||||
|
||||
public static void UnregisterEvent<TArgs>(RoutedEvent<TArgs> routedEvent, EventHandler<TArgs> handler, params Button?[] controls)
|
||||
where TArgs : RoutedEventArgs
|
||||
{
|
||||
foreach (var control in controls)
|
||||
{
|
||||
control?.RemoveHandler(routedEvent, handler);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
using Avalonia;
|
||||
|
||||
namespace Ursa.Common;
|
||||
|
||||
public static class PropertyHelper
|
||||
{
|
||||
public static void SetValue<TValue>(AvaloniaProperty<TValue> property, TValue value, params AvaloniaObject?[] elements)
|
||||
{
|
||||
foreach (var element in elements)
|
||||
{
|
||||
element?.SetValue(property, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user