mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-12 20:26:35 +08:00
线条控件
This commit is contained in:
53
AIStudio.Wpf.DiagramDesigner/Converters/MathConverter.cs
Normal file
53
AIStudio.Wpf.DiagramDesigner/Converters/MathConverter.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public enum MathOperation
|
||||
{
|
||||
Add,
|
||||
Subtract,
|
||||
Multiply,
|
||||
Divide
|
||||
}
|
||||
|
||||
public sealed class MathConverter : IValueConverter
|
||||
{
|
||||
public MathOperation Operation
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
try
|
||||
{
|
||||
double value1 = System.Convert.ToDouble(value, CultureInfo.InvariantCulture);
|
||||
double value2 = System.Convert.ToDouble(parameter, CultureInfo.InvariantCulture);
|
||||
switch (Operation)
|
||||
{
|
||||
case MathOperation.Add:
|
||||
return value1 + value2;
|
||||
case MathOperation.Divide:
|
||||
return value1 / value2;
|
||||
case MathOperation.Multiply:
|
||||
return value1 * value2;
|
||||
case MathOperation.Subtract:
|
||||
return value1 - value2;
|
||||
default:
|
||||
return Binding.DoNothing;
|
||||
}
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
return Binding.DoNothing;
|
||||
}
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return Binding.DoNothing;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user