PageRenderTime 26ms CodeModel.GetById 14ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

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

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