Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
VisibleOrHidden.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.Windows.Data;
5 using System.Globalization;
6 using System.Windows;
7 
8 namespace SiliconStudio.Presentation.ValueConverters
9 {
10  /// <summary>
11  /// This converter will convert a boolean value to a <see cref="Visibility"/> value, where false translates to <see cref="Visibility.Hidden"/>.
12  /// <see cref="ConvertBack"/> is supported.
13  /// </summary>
14  /// <remarks>If the boolean value <c>false</c> is passed as converter parameter, the visibility is inverted.</remarks>
15  /// <seealso cref="VisibleOrCollapsed"/>
16  public class VisibleOrHidden : ValueConverterBase<VisibleOrHidden>
17  {
18  /// <inheritdoc/>
19  public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
20  {
21  bool result = System.Convert.ToBoolean(value);
22  if (parameter is bool && (bool)parameter == false)
23  {
24  result = !result;
25  }
26  return result ? Visibility.Visible : Visibility.Hidden;
27  }
28 
29  /// <inheritdoc/>
30  public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
31  {
32  var visibility = (Visibility)value;
33  if (parameter is bool && (bool)parameter == false)
34  {
35  return visibility != Visibility.Visible;
36  }
37  return visibility == Visibility.Visible;
38  }
39  }
40 }
Visibility
Specifies the display state of an element.
Definition: Visibility.cs:8
override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
This converter will convert a boolean value to a Visibility value, where false translates to Visibili...
override object Convert(object value, Type targetType, object parameter, CultureInfo culture)