Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ExtendedOrSingle.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.Controls;
6 
7 namespace SiliconStudio.Presentation.ValueConverters
8 {
9  /// <summary>
10  /// This converter will convert a boolean value to a <see cref="SelectionMode"/> value, where <c>false</c> translates to <see cref="SelectionMode.Single"/>
11  /// and <c>true></c> translates to <see cref="SelectionMode.Extended"/>.
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  public class ExtendedOrSingle : ValueConverterBase<ExtendedOrSingle>
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 ? SelectionMode.Extended : SelectionMode.Single;
26  }
27 
28  /// <inheritdoc/>
29  public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
30  {
31  var selectionMode = (SelectionMode)value;
32  if (parameter is bool && (bool)parameter == false)
33  {
34  return selectionMode != SelectionMode.Extended;
35  }
36  return selectionMode == SelectionMode.Extended;
37  }
38  }
39 
40 }
override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
This converter will convert a boolean value to a SelectionMode value, where false translates to Selec...
override object Convert(object value, Type targetType, object parameter, CultureInfo culture)