Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
SumThickness.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 using System.Windows.Data;
7 
8 using SiliconStudio.Presentation.MarkupExtensions;
9 
10 namespace SiliconStudio.Presentation.ValueConverters
11 {
12  /// <summary>
13  /// This converter will sum a given <see cref="Thickness"/> with a <see cref="Thickness"/> passed as parameter. You can use
14  /// the <see cref="ThicknessExtension"/> markup extension to easily pass one, with the following syntax: {sskk:Thickness (arguments)}.
15  /// </summary>
16  [ValueConversion(typeof(Thickness), typeof(Thickness))]
17  public class SumThickness : ValueConverterBase<SumThickness>
18  {
19  /// <inheritdoc/>
20  public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
21  {
22  if (!(value is Thickness))
23  {
24  throw new ArgumentException("The value of the ConvertBack method of this converter must be a an instance of the Thickness structure.");
25  }
26  if (!(parameter is Thickness))
27  {
28  throw new ArgumentException("The parameter of the ConvertBack method of this converter must be a an instance of the Thickness structure.");
29  }
30 
31  var sizeValue = (Thickness)value;
32  var sizeParameter = (Thickness)parameter;
33  var result = new Thickness(sizeValue.Left + sizeParameter.Left, sizeValue.Top + sizeParameter.Top, sizeValue.Right + sizeParameter.Right, sizeValue.Bottom + sizeParameter.Bottom);
34  return result;
35  }
36 
37  /// <inheritdoc/>
38  public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
39  {
40  if (!(value is Thickness))
41  {
42  throw new ArgumentException("The value of the ConvertBack method of this converter must be a an instance of the Thickness structure.");
43  }
44  if (!(parameter is Thickness))
45  {
46  throw new ArgumentException("The parameter of the ConvertBack method of this converter must be a an instance of the Thickness structure.");
47  }
48  var sizeValue = (Thickness)value;
49  var sizeParameter = (Thickness)parameter;
50 
51  var result = new Thickness(sizeValue.Left - sizeParameter.Left, sizeValue.Top - sizeParameter.Top, sizeValue.Right - sizeParameter.Right, sizeValue.Bottom - sizeParameter.Bottom);
52  return result;
53  }
54  }
55 }
override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
Definition: SumThickness.cs:38
override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
Definition: SumThickness.cs:20
This converter will sum a given Thickness with a Thickness passed as parameter. You can use the Thick...
Definition: SumThickness.cs:17