ResourceNodeExtensions.cs 842 B

12345678910111213141516171819202122
  1. using Avalonia;
  2. using Avalonia.Controls;
  3. using System;
  4. namespace SukiUI.Extensions
  5. {
  6. public static class ResourceNodeExtensions
  7. {
  8. /// <summary>
  9. /// Finds the specified resource by searching up the logical tree and then global styles.
  10. /// </summary>
  11. /// <param name="control">The control.</param>
  12. /// <param name="key">The resource key.</param>
  13. /// <returns>The resource, or <see cref="AvaloniaProperty.UnsetValue"/> if not found.</returns>
  14. public static object FindRequiredResource(this IResourceHost? control, object key)
  15. {
  16. control = control ?? throw new ArgumentNullException(nameof(control));
  17. return control.FindResource(key) ?? throw new ArgumentNullException("Could not find required resource with the specified key");
  18. }
  19. }
  20. }