Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
VisibleOrCollapsed.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.Globalization;
5 using System.Windows;
6 
7 namespace SiliconStudio.Presentation.ValueConverters
8 {
9  /// <summary>
10  /// This converter will convert a boolean value to a <see cref="Visibility"/> value, where false translates to <see cref="Visibility.Collapsed"/>.
11  /// <see cref="ConvertBack"/> is supported.
12  /// </summary>
13  /// <remarks>If the boolean value <c>false</c> is passed as converter parameter, the visibility is inverted.</remarks>
14  /// <seealso cref="VisibleOrHidden"/>
15  public class VisibleOrCollapsed : ValueConverterBase<VisibleOrCollapsed>
16  {
17  /// <inheritdoc/>
18  public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
19  {
20  bool result = System.Convert.ToBoolean(value);
21  if (parameter is bool && (bool)parameter == false)
22  {
23  result = !result;
24  }
25  return result ? Visibility.Visible : Visibility.Collapsed;
26  }
27 
28  /// <inheritdoc/>
29  public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
30  {
31  var visibility = (Visibility)value;
32  if (parameter is bool && (bool)parameter == false)
33  {
34  return visibility != Visibility.Visible;
35  }
36  return visibility == Visibility.Visible;
37  }
38  }
39 }
This converter will convert a boolean value to a Visibility value, where false translates to Visibili...
Visibility
Specifies the display state of an element.
Definition: Visibility.cs:8
override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
override object Convert(object value, Type targetType, object parameter, CultureInfo culture)