feat: refactor to simplify null control property and event initialization.

This commit is contained in:
rabbitism
2024-02-07 19:04:51 +08:00
parent 41aa97a160
commit 7e57a0c0ef
13 changed files with 96 additions and 239 deletions

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}
}