Files
aistudio-wpf-diagram/AIStudio.Wpf.DiagramDesigner/Converters/ConectorValueConverter.cs

53 lines
1.7 KiB
C#
Raw Normal View History

2022-10-28 22:45:39 +08:00
using AIStudio.Wpf.DiagramDesigner;
2021-07-23 09:42:22 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Imaging;
2022-10-28 22:45:39 +08:00
namespace AIStudio.Wpf.DiagramDesigner
2021-07-23 09:42:22 +08:00
{
public class ConectorValueConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
2023-04-19 22:26:04 +08:00
if (values == null || values.Length < 2)
2021-07-23 09:42:22 +08:00
{
throw new NotImplementedException();
}
2023-04-19 22:26:04 +08:00
if (values[0] is double && values[2] is ValueType)
2021-07-23 09:42:22 +08:00
{
double connectorValue = (double)values[0];
2023-04-19 22:26:04 +08:00
string connectorString = values[1] as string;
ValueType valueTypePoint = (ValueType)values[2];
2021-07-23 09:42:22 +08:00
2023-04-19 22:26:04 +08:00
if (valueTypePoint == ValueType.Bool)
2021-07-23 09:42:22 +08:00
{
return (connectorValue == 0) ? "F" : "T";
}
2023-04-19 22:26:04 +08:00
else if (valueTypePoint == ValueType.Int)
2021-07-23 09:42:22 +08:00
{
return connectorValue.ToString("0");
}
2023-04-19 22:26:04 +08:00
else if (valueTypePoint == ValueType.Real)
2021-07-23 09:42:22 +08:00
{
return connectorValue.ToString("f3");
}
2023-04-19 22:26:04 +08:00
else
{
return connectorString;
}
2021-07-23 09:42:22 +08:00
}
return null;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}