[amd64/tramp] hide interpreter specific trampoline behind ifdef
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / System.Activities.Presentation / System / Activities / Presentation / Base / Core / Internal / PropertyEditing / FromExpression / Framework / Data / BoolToVisibilityCollpasedConverter.cs
1 // -------------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All Rights Reserved.
3 // -------------------------------------------------------------------
4 //From \\authoring\Sparkle\Source\1.0.1083.0\Common\Source\Framework\Data
5 namespace System.Activities.Presentation.Internal.PropertyEditing.FromExpression.Framework.Data
6 {
7     using System;
8     using System.ComponentModel;
9     using System.Globalization;
10     using System.Reflection;
11     using System.Windows;
12     using System.Windows.Controls;
13     using System.Windows.Data;
14     using System.Diagnostics.CodeAnalysis;
15
16     // <summary>
17     // (bool-to-Visibility) Maps true to Visible and false to Collapsed.
18     // </summary>
19
20     [SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses")]
21     internal class BoolToVisibilityCollapsedConverter : IValueConverter
22     {
23         bool invertBoolean = false;
24
25         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
26         public bool InvertBoolean
27         {
28             get { return this.invertBoolean; }
29             set { this.invertBoolean = value; }
30         }
31
32         // IValueConverter Implementation
33         public object ConvertBack(object o, Type targetType, object parameter, CultureInfo culture)
34         {
35             Visibility visibility = (Visibility)o;
36             return ((visibility == Visibility.Visible) ^ this.invertBoolean);
37         }
38
39         public object Convert(object o, Type targetType, object parameter, CultureInfo culture)
40         {
41             Visibility result = Visibility.Collapsed;
42
43             if (o is Nullable<bool>)
44             {
45                 if ((((Nullable<bool>)o).Value) ^ this.invertBoolean)
46                 {
47                     result = Visibility.Visible;
48                 }
49             }
50             else if (o is bool)
51             {
52                 if (((bool)o) ^ this.invertBoolean)
53                 {
54                     result = Visibility.Visible;
55                 }
56             }
57             return result;
58         }
59     }
60
61 }