36 lines
1.6 KiB
C#
36 lines
1.6 KiB
C#
using System;
|
|
using System.Windows.Data;
|
|
|
|
namespace JD.WPF.Converters
|
|
{
|
|
public class MultiplyConverter : IValueConverter
|
|
{
|
|
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
|
{
|
|
if (value is int)
|
|
return (int)value * System.Convert.ToInt32(parameter);
|
|
if (value is uint && parameter is uint)
|
|
return (uint)value * System.Convert.ToUInt32(parameter);
|
|
if (value is float && parameter is float)
|
|
return (float)value * System.Convert.ToSingle(parameter);
|
|
if (value is double && parameter is double)
|
|
return (double)value * System.Convert.ToDouble(parameter);
|
|
|
|
throw new NotSupportedException("Either value and parameter have not the same type, or their type is not supported. ");
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
|
{
|
|
if (value is int && parameter is int)
|
|
return (int)value / System.Convert.ToInt32(parameter);
|
|
if (value is uint && parameter is uint)
|
|
return (uint)value / System.Convert.ToUInt32(parameter);
|
|
if (value is float && parameter is float)
|
|
return (float)value / System.Convert.ToSingle(parameter);
|
|
if (value is double && parameter is double)
|
|
return (double)value / System.Convert.ToDouble(parameter);
|
|
|
|
throw new NotSupportedException("Either value and parameter have not the same type, or their type is not supported. ");
|
|
}
|
|
}
|
|
}
|