PageRenderTime 40ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/ExpressInteropBinding/Microsoft.ServiceModel.Interop.ExtensionUtils/ConfigurationWizard/View/BooleanToVisibilityConverter.cs

#
C# | 74 lines | 34 code | 9 blank | 31 comment | 3 complexity | bc891f6513323517b552701a6eef1dc4 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, Apache-2.0
  1. // <copyright file="BooleanToVisibilityConverter.cs" company="Microsoft Corporation">
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. // </copyright>
  4. namespace Microsoft.ServiceModel.Interop.ConfigurationWizard.View
  5. {
  6. using System;
  7. using System.Globalization;
  8. using System.Windows;
  9. using System.Windows.Data;
  10. /// <summary>
  11. /// Boolean to visibility type converter
  12. /// </summary>
  13. public class BooleanToVisibilityConverter : IValueConverter
  14. {
  15. /// <summary>
  16. /// Initializes a new instance of the BooleanToVisibilityConverter class
  17. /// </summary>
  18. public BooleanToVisibilityConverter()
  19. {
  20. this.WhenTrue = Visibility.Visible;
  21. this.WhenFalse = Visibility.Collapsed;
  22. }
  23. /// <summary>
  24. /// Gets or sets the visibility settings when the converter takes a value equals to false
  25. /// </summary>
  26. public Visibility WhenFalse { get; set; }
  27. /// <summary>
  28. /// Gets or sets the visibility settings when the converter takes a value equals to true
  29. /// </summary>
  30. public Visibility WhenTrue { get; set; }
  31. /// <summary>
  32. /// Converts an object to a target type
  33. /// </summary>
  34. /// <param name="value">Object to convert</param>
  35. /// <param name="targetType">Target type</param>
  36. /// <param name="parameter">Custom parameter</param>
  37. /// <param name="culture">Culture info</param>
  38. /// <returns>A valid instance of the target type</returns>
  39. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  40. {
  41. var nullable = value as bool?;
  42. if (!nullable.HasValue)
  43. {
  44. throw new ArgumentException("Value must be Boolean.", "value");
  45. }
  46. if (targetType != typeof(Visibility))
  47. {
  48. throw new ArgumentException("Must convert to Visibility.", "targetType");
  49. }
  50. return nullable.Value ? this.WhenTrue : this.WhenFalse;
  51. }
  52. /// <summary>
  53. /// Converts a value
  54. /// </summary>
  55. /// <param name="value">The value that is produced by the binding target</param>
  56. /// <param name="targetType">The type to convert to</param>
  57. /// <param name="parameter">The converter parameter to use</param>
  58. /// <param name="culture">The culture to use in the converter</param>
  59. /// <returns>A converted value. If the method returns null, the valid null value is used</returns>
  60. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  61. {
  62. throw new NotImplementedException();
  63. }
  64. }
  65. }