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