ControlExtensions.cs 1.0 KB

1234567891011121314151617181920212223242526
  1. using Avalonia.Controls;
  2. using System;
  3. namespace SukiUI.Extensions
  4. {
  5. /// <summary>
  6. /// Adds common functionality to <see cref="Control"/>.
  7. /// </summary>
  8. public static class ControlExtensions
  9. {
  10. /// <summary>
  11. /// Finds the named control in the scope of the specified control.
  12. /// </summary>
  13. /// <typeparam name="T">The type of the control to find.</typeparam>
  14. /// <param name="control">The control to look in.</param>
  15. /// <param name="name">The name of the control to find.</param>
  16. /// <returns>The control or throws if not found.</returns>
  17. /// <exception cref="ArgumentNullException" />
  18. public static T FindRequiredControl<T>(this Control? control, string name) where T : Control
  19. {
  20. control = control ?? throw new ArgumentNullException(nameof(control));
  21. return control.FindControl<T>(name) ?? throw new ArgumentNullException("Could not find required control with the specified name");
  22. }
  23. }
  24. }