UserControl.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright (c) The Avalonia Project. All rights reserved.
  2. // Licensed under the MIT license. See licence.md file in the project root for full license information.
  3. using System;
  4. using Avalonia.Styling;
  5. namespace Avalonia.Controls
  6. {
  7. /// <summary>
  8. /// Provides the base class for defining a new control that encapsulates related existing controls and provides its own logic.
  9. /// </summary>
  10. public class UserControl : ContentControl, IStyleable, INameScope
  11. {
  12. private readonly NameScope _nameScope = new NameScope();
  13. /// <inheritdoc/>
  14. event EventHandler<NameScopeEventArgs> INameScope.Registered
  15. {
  16. add { _nameScope.Registered += value; }
  17. remove { _nameScope.Registered -= value; }
  18. }
  19. /// <inheritdoc/>
  20. event EventHandler<NameScopeEventArgs> INameScope.Unregistered
  21. {
  22. add { _nameScope.Unregistered += value; }
  23. remove { _nameScope.Unregistered -= value; }
  24. }
  25. /// <inheritdoc/>
  26. Type IStyleable.StyleKey => typeof(UserControl);
  27. /// <inheritdoc/>
  28. void INameScope.Register(string name, object element)
  29. {
  30. _nameScope.Register(name, element);
  31. }
  32. /// <inheritdoc/>
  33. object INameScope.Find(string name)
  34. {
  35. return _nameScope.Find(name);
  36. }
  37. /// <inheritdoc/>
  38. void INameScope.Unregister(string name)
  39. {
  40. _nameScope.Unregister(name);
  41. }
  42. }
  43. }