ContentControlStyle.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright (c) The Perspex 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.Linq;
  4. using Perspex.Controls;
  5. using Perspex.Controls.Presenters;
  6. using Perspex.Controls.Primitives;
  7. using Perspex.Controls.Templates;
  8. using Perspex.Styling;
  9. namespace Perspex.Themes.Default
  10. {
  11. /// <summary>
  12. /// The default style for the <see cref="ContentControl"/> control.
  13. /// </summary>
  14. public class ContentControlStyle : Styles
  15. {
  16. /// <summary>
  17. /// Initializes a new instance of the <see cref="ContentControlStyle"/> class.
  18. /// </summary>
  19. public ContentControlStyle()
  20. {
  21. AddRange(new[]
  22. {
  23. new Style(x => x.OfType<ContentControl>())
  24. {
  25. Setters = new[]
  26. {
  27. new Setter(TemplatedControl.TemplateProperty, new FuncControlTemplate<ContentControl>(Template)),
  28. },
  29. },
  30. });
  31. }
  32. /// <summary>
  33. /// The default template for a <see cref="ContentControl"/> control.
  34. /// </summary>
  35. /// <param name="control">The control being styled.</param>
  36. /// <returns>The root of the instantiated template.</returns>
  37. public static Control Template(ContentControl control)
  38. {
  39. return new Border
  40. {
  41. [~Border.BackgroundProperty] = control[~TemplatedControl.BackgroundProperty],
  42. Child = new ContentPresenter
  43. {
  44. Name = "contentPresenter",
  45. [~ContentPresenter.ContentProperty] = control[~ContentControl.ContentProperty],
  46. }
  47. };
  48. }
  49. }
  50. }