TileBindingContentAdaptive.cs 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // ******************************************************************
  2. // Copyright (c) Microsoft. All rights reserved.
  3. // This code is licensed under the MIT License (MIT).
  4. // THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  5. // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  6. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  7. // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  8. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  9. // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
  10. // THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
  11. // ******************************************************************
  12. using System.Collections.Generic;
  13. using Microsoft.Toolkit.Uwp.Notifications.Adaptive;
  14. namespace Microsoft.Toolkit.Uwp.Notifications
  15. {
  16. /// <summary>
  17. /// Supported on all sizes. This is the recommended way of specifying your Tile content. Adaptive Tile templates are the de-facto choice for Windows 10, and you can create a wide variety of custom Tiles through adaptive.
  18. /// </summary>
  19. public sealed class TileBindingContentAdaptive : ITileBindingContent
  20. {
  21. /// <summary>
  22. /// <see cref="AdaptiveText"/>, <see cref="AdaptiveImage"/>, and <see cref="AdaptiveGroup"/> objects can be added as children. The children are displayed in a vertical StackPanel fashion.
  23. /// </summary>
  24. public IList<ITileBindingContentAdaptiveChild> Children { get; private set; } = new List<ITileBindingContentAdaptiveChild>();
  25. /// <summary>
  26. /// An optional background image that gets displayed behind all the Tile content, full bleed.
  27. /// </summary>
  28. public TileBackgroundImage BackgroundImage { get; set; }
  29. /// <summary>
  30. /// An optional peek image that animates in from the top of the Tile.
  31. /// </summary>
  32. public TilePeekImage PeekImage { get; set; }
  33. /// <summary>
  34. /// Controls the text stacking (vertical alignment) of the entire binding element.
  35. /// </summary>
  36. public TileTextStacking TextStacking { get; set; } = Element_TileBinding.DEFAULT_TEXT_STACKING;
  37. internal TileTemplateNameV3 GetTemplateName(TileSize size)
  38. {
  39. return TileSizeToAdaptiveTemplateConverter.Convert(size);
  40. }
  41. internal void PopulateElement(Element_TileBinding binding, TileSize size)
  42. {
  43. // Assign properties
  44. binding.TextStacking = TextStacking;
  45. // Add the background image if there's one
  46. if (BackgroundImage != null)
  47. {
  48. // And add it as a child
  49. binding.Children.Add(BackgroundImage.ConvertToElement());
  50. }
  51. // Add the peek image if there's one
  52. if (PeekImage != null)
  53. {
  54. var el = PeekImage.ConvertToElement();
  55. binding.Children.Add(el);
  56. }
  57. // And then add all the children
  58. foreach (var child in Children)
  59. {
  60. binding.Children.Add(ConvertToBindingChildElement(child));
  61. }
  62. }
  63. private static IElement_TileBindingChild ConvertToBindingChildElement(ITileBindingContentAdaptiveChild child)
  64. {
  65. return (IElement_TileBindingChild)AdaptiveHelper.ConvertToElement(child);
  66. }
  67. }
  68. }