committed by
GitHub
17 changed files with 109 additions and 165 deletions
@ -1,10 +1,24 @@ |
|||||
using System; |
using System.Threading; |
||||
|
|
||||
namespace Avalonia.Controls |
namespace Avalonia.Controls; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Represents the event arguments of <see cref="IResourceHost.ResourcesChanged"/>.
|
||||
|
/// The <see cref="SequenceNumber"/> identifies the changes.
|
||||
|
/// </summary>
|
||||
|
/// <param name="SequenceNumber">The sequence number used to identify the changes.</param>
|
||||
|
/// <remarks>
|
||||
|
/// For performance reasons, this type is a struct.
|
||||
|
/// Avoid using a default instance of this type or its default constructor, call <see cref="Create"/> instead.
|
||||
|
/// </remarks>
|
||||
|
public readonly record struct ResourcesChangedEventArgs(int SequenceNumber) |
||||
{ |
{ |
||||
// TODO12: change this to be a struct, remove ResourcesChangedToken
|
private static int s_lastSequenceNumber; |
||||
public class ResourcesChangedEventArgs : EventArgs |
|
||||
{ |
/// <summary>
|
||||
public static new readonly ResourcesChangedEventArgs Empty = new ResourcesChangedEventArgs(); |
/// Creates a new instance of <see cref="ResourcesChangedEventArgs"/> with an auto-incremented sequence number.
|
||||
} |
/// </summary>
|
||||
|
/// <returns></returns>
|
||||
|
public static ResourcesChangedEventArgs Create() |
||||
|
=> new(Interlocked.Increment(ref s_lastSequenceNumber)); |
||||
} |
} |
||||
|
|||||
@ -1,45 +0,0 @@ |
|||||
using System; |
|
||||
using Avalonia.LogicalTree; |
|
||||
|
|
||||
namespace Avalonia.Controls; |
|
||||
|
|
||||
internal static class ResourcesChangedHelper |
|
||||
{ |
|
||||
internal static void NotifyHostedResourcesChanged(this IResourceHost host, ResourcesChangedToken token) |
|
||||
{ |
|
||||
if (host is IResourceHost2 host2) |
|
||||
host2.NotifyHostedResourcesChanged(token); |
|
||||
else |
|
||||
host.NotifyHostedResourcesChanged(ResourcesChangedEventArgs.Empty); |
|
||||
} |
|
||||
|
|
||||
internal static void NotifyResourcesChanged(this ILogical logical, ResourcesChangedToken token) |
|
||||
{ |
|
||||
if (logical is StyledElement styledElement) |
|
||||
styledElement.NotifyResourcesChanged(token); |
|
||||
else |
|
||||
logical.NotifyResourcesChanged(ResourcesChangedEventArgs.Empty); |
|
||||
} |
|
||||
|
|
||||
internal static void SubscribeToResourcesChanged( |
|
||||
this IResourceHost host, |
|
||||
EventHandler<ResourcesChangedEventArgs> handler, |
|
||||
EventHandler<ResourcesChangedToken> handler2) |
|
||||
{ |
|
||||
if (host is IResourceHost2 host2) |
|
||||
host2.ResourcesChanged2 += handler2; |
|
||||
else |
|
||||
host.ResourcesChanged += handler; |
|
||||
} |
|
||||
|
|
||||
internal static void UnsubscribeFromResourcesChanged( |
|
||||
this IResourceHost host, |
|
||||
EventHandler<ResourcesChangedEventArgs> handler, |
|
||||
EventHandler<ResourcesChangedToken> handler2) |
|
||||
{ |
|
||||
if (host is IResourceHost2 host2) |
|
||||
host2.ResourcesChanged2 -= handler2; |
|
||||
else |
|
||||
host.ResourcesChanged -= handler; |
|
||||
} |
|
||||
} |
|
||||
@ -1,11 +0,0 @@ |
|||||
using System.Threading; |
|
||||
|
|
||||
namespace Avalonia.Controls; |
|
||||
|
|
||||
internal record struct ResourcesChangedToken(int SequenceNumber) |
|
||||
{ |
|
||||
private static int s_lastSequenceNumber; |
|
||||
|
|
||||
public static ResourcesChangedToken Create() |
|
||||
=> new(Interlocked.Increment(ref s_lastSequenceNumber)); |
|
||||
} |
|
||||
Loading…
Reference in new issue