AdaptiveGroup.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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;
  13. using System.Collections.Generic;
  14. using Microsoft.Toolkit.Uwp.Notifications.Adaptive.Elements;
  15. namespace Microsoft.Toolkit.Uwp.Notifications
  16. {
  17. /// <summary>
  18. /// Groups semantically identify that the content in the group must either be displayed as a whole, or not displayed if it cannot fit. Groups also allow creating multiple columns. Supported on Tiles since RTM. Supported on Toasts since Anniversary Update.
  19. /// </summary>
  20. public sealed class AdaptiveGroup : ITileBindingContentAdaptiveChild, IAdaptiveChild, IToastBindingGenericChild
  21. {
  22. /// <summary>
  23. /// The only valid children of groups are <see cref="AdaptiveSubgroup"/>. Each subgroup is displayed as a separate vertical column. Note that you must include at least one subgroup in your group, otherwise an <see cref="InvalidOperationException"/> will be thrown when you try to retrieve the XML for the notification.
  24. /// </summary>
  25. public IList<AdaptiveSubgroup> Children { get; private set; } = new List<AdaptiveSubgroup>();
  26. internal Element_AdaptiveGroup ConvertToElement()
  27. {
  28. if (Children.Count == 0)
  29. {
  30. throw new InvalidOperationException("Groups must have at least one child subgroup. The Children property had zero items in it.");
  31. }
  32. Element_AdaptiveGroup group = new Element_AdaptiveGroup();
  33. foreach (var subgroup in Children)
  34. {
  35. group.Children.Add(subgroup.ConvertToElement());
  36. }
  37. return group;
  38. }
  39. }
  40. }