BindableProgressBarValue.cs 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. namespace Microsoft.Toolkit.Uwp.Notifications
  13. {
  14. // Note that this code is NOT compiled for WinRT.
  15. // WinRT uses a different binding system since it doesn't support implicit type converters.
  16. #if !WINRT
  17. /// <summary>
  18. /// A binding value for doubles.
  19. /// </summary>
  20. public sealed class BindableProgressBarValue
  21. {
  22. /// <summary>
  23. /// Raw value is used for the implicit converter case, where dev provided a raw double. We store the raw value,
  24. /// so that later on when generating the XML, we can provide this value rather than binding syntax.
  25. /// </summary>
  26. internal AdaptiveProgressBarValue RawValue { get; private set; }
  27. internal bool RawIsIndeterminate { get; private set; }
  28. /// <summary>
  29. /// The name that maps to your binding data value.
  30. /// </summary>
  31. public string BindingName { get; set; }
  32. /// <summary>
  33. /// Initializes a new binding for a double value, with the required binding value name. Do NOT include surrounding {} brackets.
  34. /// </summary>
  35. /// <param name="bindingName">The name that maps to your binding data value.</param>
  36. public BindableProgressBarValue(string bindingName)
  37. {
  38. BindingName = bindingName;
  39. }
  40. /// <summary>
  41. /// Private constructor used by the implicit converter to assign the raw value.
  42. /// </summary>
  43. private BindableProgressBarValue()
  44. {
  45. }
  46. internal string ToXmlString()
  47. {
  48. if (BindingName != null)
  49. {
  50. return "{" + BindingName + "}";
  51. }
  52. if (RawValue != null)
  53. {
  54. return RawValue.ToXmlString();
  55. }
  56. return null;
  57. }
  58. /// <summary>
  59. /// Creates a <see cref="BindableProgressBarValue"/> that has a raw value assigned.
  60. /// </summary>
  61. /// <param name="v">The raw value</param>
  62. public static implicit operator BindableProgressBarValue(AdaptiveProgressBarValue v)
  63. {
  64. return new BindableProgressBarValue()
  65. {
  66. RawValue = v
  67. };
  68. }
  69. /// <summary>
  70. /// Returns the raw value of the <see cref="BindableProgressBarValue"/>.
  71. /// </summary>
  72. /// <param name="b">The <see cref="BindableProgressBarValue"/> to obtain the raw value from.</param>
  73. public static implicit operator AdaptiveProgressBarValue(BindableProgressBarValue b)
  74. {
  75. return b.RawValue;
  76. }
  77. /// <summary>
  78. /// Creates an <see cref="BindableProgressBarValue"/> that has tbe raw double value.
  79. /// </summary>
  80. /// <param name="d">The raw value</param>
  81. public static implicit operator BindableProgressBarValue(double d)
  82. {
  83. return AdaptiveProgressBarValue.FromValue(d);
  84. }
  85. }
  86. #endif
  87. }