首次上传
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
using System.Windows;
|
||||
|
||||
namespace MECF.Framework.UI.Core.Converters
|
||||
{
|
||||
public class BoolCollapsedConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is bool isVisible)
|
||||
{
|
||||
if (parameter is bool isReverse && isReverse)
|
||||
isVisible = !isVisible;
|
||||
|
||||
return isVisible ? Visibility.Visible : Visibility.Collapsed;
|
||||
}
|
||||
|
||||
return Visibility.Visible;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace MECF.Framework.UI.Core.Converters
|
||||
{
|
||||
public class BoolReverseConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is bool bValue)
|
||||
return !bValue;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is bool bValue)
|
||||
return !bValue;
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Media;
|
||||
using Aitex.Core.RT.Log;
|
||||
|
||||
namespace MECF.Framework.UI.Core.Converters
|
||||
{
|
||||
public class BoolSensorConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
|
||||
return (bool)value ? "LightGreen" : "Gray";
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class BoolWaterConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
|
||||
return (bool)value ? "#5CACEE" : "Transport";
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class ReserveBoolSensorConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
|
||||
return !(bool)value ? "LightGreen" : "Gray";
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace MECF.Framework.UI.Core.Converters
|
||||
{
|
||||
public class BoolVisibilityConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is bool isVisible)
|
||||
{
|
||||
if (parameter is bool isReverse && isReverse)
|
||||
isVisible = !isVisible;
|
||||
|
||||
return isVisible ? Visibility.Visible : Visibility.Hidden;
|
||||
}
|
||||
|
||||
return Visibility.Visible;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Shapes;
|
||||
using Brushes = System.Windows.Media.Brushes;
|
||||
|
||||
namespace Aitex.Core.UI.Converters
|
||||
{
|
||||
class CenterBorderGapMaskConverter : IMultiValueConverter
|
||||
{
|
||||
// Methods
|
||||
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
Type type = typeof(double);
|
||||
if (values == null
|
||||
|| values.Length != 3
|
||||
|| values[0] == null
|
||||
|| values[1] == null
|
||||
|| values[2] == null
|
||||
|| !type.IsAssignableFrom(values[0].GetType())
|
||||
|| !type.IsAssignableFrom(values[1].GetType())
|
||||
|| !type.IsAssignableFrom(values[2].GetType()))
|
||||
{
|
||||
return DependencyProperty.UnsetValue;
|
||||
}
|
||||
|
||||
double pixels = (double)values[0];
|
||||
double width = (double)values[1];
|
||||
double height = (double)values[2];
|
||||
if ((width == 0.0) || (height == 0.0))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
Grid visual = new Grid();
|
||||
visual.Width = width;
|
||||
visual.Height = height;
|
||||
ColumnDefinition colDefinition1 = new ColumnDefinition();
|
||||
ColumnDefinition colDefinition2 = new ColumnDefinition();
|
||||
ColumnDefinition colDefinition3 = new ColumnDefinition();
|
||||
colDefinition1.Width = new GridLength(1.0, GridUnitType.Star);
|
||||
colDefinition2.Width = new GridLength(pixels);
|
||||
colDefinition3.Width = new GridLength(1.0, GridUnitType.Star);
|
||||
visual.ColumnDefinitions.Add(colDefinition1);
|
||||
visual.ColumnDefinitions.Add(colDefinition2);
|
||||
visual.ColumnDefinitions.Add(colDefinition3);
|
||||
RowDefinition rowDefinition1 = new RowDefinition();
|
||||
RowDefinition rowDefinition2 = new RowDefinition();
|
||||
rowDefinition1.Height = new GridLength(height / 2.0);
|
||||
rowDefinition2.Height = new GridLength(1.0, GridUnitType.Star);
|
||||
visual.RowDefinitions.Add(rowDefinition1);
|
||||
visual.RowDefinitions.Add(rowDefinition2);
|
||||
Rectangle rectangle1 = new Rectangle();
|
||||
Rectangle rectangle2 = new Rectangle();
|
||||
Rectangle rectangle3 = new Rectangle();
|
||||
rectangle1.Fill = Brushes.Black;
|
||||
rectangle2.Fill = Brushes.Black;
|
||||
rectangle3.Fill = Brushes.Black;
|
||||
Grid.SetRowSpan(rectangle1, 2);
|
||||
Grid.SetRow(rectangle1, 0);
|
||||
Grid.SetColumn(rectangle1, 0);
|
||||
Grid.SetRow(rectangle2, 1);
|
||||
Grid.SetColumn(rectangle2, 1);
|
||||
Grid.SetRowSpan(rectangle3, 2);
|
||||
Grid.SetRow(rectangle3, 0);
|
||||
Grid.SetColumn(rectangle3, 2);
|
||||
visual.Children.Add(rectangle1);
|
||||
visual.Children.Add(rectangle2);
|
||||
visual.Children.Add(rectangle3);
|
||||
return new VisualBrush(visual);
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
|
||||
{
|
||||
return new object[] { Binding.DoNothing };
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace Aitex.Core.UI.Converters
|
||||
{
|
||||
/// <summary>
|
||||
/// 输入数值检测
|
||||
/// </summary>
|
||||
public class ColorConverter_IsTestOK : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value == null || value.ToString().Length == 0)
|
||||
return new SolidColorBrush(Colors.Gray);
|
||||
if (value.ToString() == "OK")
|
||||
return new SolidColorBrush(Colors.Green);
|
||||
else if (value.ToString() == "NG")
|
||||
return new SolidColorBrush(Colors.MediumVioletRed);
|
||||
else
|
||||
return new SolidColorBrush(Colors.Gray);
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Media;
|
||||
using Aitex.Core.RT.Log;
|
||||
|
||||
namespace Aitex.Core.UI.Converters
|
||||
{
|
||||
public class ColorToBrushConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
try
|
||||
{
|
||||
Color color = (Color)value;
|
||||
return new SolidColorBrush(color);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LOG.Write(ex);
|
||||
}
|
||||
return Brushes.Black;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
try
|
||||
{
|
||||
Brush brush = (SolidColorBrush)value;
|
||||
Color color = (Color)ColorConverter.ConvertFromString(brush.ToString());
|
||||
return color;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LOG.Write(ex);
|
||||
}
|
||||
return Colors.Black;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace MECF.Framework.UI.Core.Converters;
|
||||
|
||||
public class ColorToStringConverter: IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if(value is Color color)
|
||||
return $"#{color.A:X2}{color.R:X2}{color.G:X2}{color.B:X2}";
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is string str)
|
||||
{
|
||||
const string pattern = @"^#([A-Fa-f0-9]{8})$";
|
||||
if(Regex.IsMatch(str, pattern))
|
||||
return ColorConverter.ConvertFromString(str);
|
||||
}
|
||||
|
||||
return Colors.Red;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace MECF.Framework.UI.Core.Converters
|
||||
{
|
||||
public class DoubleToStringConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value == null)
|
||||
return "";
|
||||
|
||||
if(value is double dbl)
|
||||
return dbl.ToString(CultureInfo.InvariantCulture);
|
||||
|
||||
return value.ToString();
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if(value == null)
|
||||
return double.NaN;
|
||||
|
||||
if (double.TryParse(value.ToString(), out var dbl))
|
||||
return dbl;
|
||||
|
||||
return double.NaN;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace MECF.Framework.UI.Core.Converters;
|
||||
|
||||
public class EnumDescriptionConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
var myEnum = (Enum)value;
|
||||
if (myEnum == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var description = GetEnumDescription(myEnum);
|
||||
return !string.IsNullOrEmpty(description) ? description : myEnum.ToString();
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
private string GetEnumDescription(Enum enumObj)
|
||||
{
|
||||
if (enumObj == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
var fieldInfo = enumObj.GetType().GetField(enumObj.ToString());
|
||||
|
||||
var attribArray = fieldInfo.GetCustomAttributes(false);
|
||||
|
||||
if (attribArray.Length == 0)
|
||||
{
|
||||
return enumObj.ToString();
|
||||
}
|
||||
|
||||
var attrib = attribArray[0] as DescriptionAttribute;
|
||||
return attrib.Description;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace MECF.Framework.UI.Core.Converters;
|
||||
|
||||
public class EnumDisplayConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
var myEnum = (Enum)value;
|
||||
if (myEnum == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var description = GetEnumDisplay(myEnum);
|
||||
return !string.IsNullOrEmpty(description) ? description : myEnum.ToString();
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
private string GetEnumDisplay(Enum enumObj)
|
||||
{
|
||||
if (enumObj == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
var fieldInfo = enumObj.GetType().GetField(enumObj.ToString());
|
||||
|
||||
var attribArray = fieldInfo.GetCustomAttributes(false);
|
||||
|
||||
if (attribArray.Length == 0)
|
||||
{
|
||||
return enumObj.ToString();
|
||||
}
|
||||
|
||||
var attrib = attribArray[0] as DisplayAttribute;
|
||||
return attrib?.Name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,274 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Media;
|
||||
using System.Windows;
|
||||
using Aitex.Core.RT.Log;
|
||||
|
||||
namespace Aitex.Core.UI.Converters
|
||||
{
|
||||
public class LineColorConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
try
|
||||
{
|
||||
Color color = (Color)value;
|
||||
return new SolidColorBrush(color);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LOG.Write(ex);
|
||||
}
|
||||
return Brushes.Black;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
try
|
||||
{
|
||||
Brush brush = (SolidColorBrush)value;
|
||||
Color color = (Color)ColorConverter.ConvertFromString(brush.ToString());
|
||||
return color;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LOG.Write(ex);
|
||||
}
|
||||
return Colors.Black;
|
||||
}
|
||||
}
|
||||
|
||||
public class bool2VisibilityConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
try
|
||||
{
|
||||
if ((bool)value)
|
||||
return Visibility.Visible;
|
||||
return Visibility.Hidden;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LOG.Write(ex);
|
||||
}
|
||||
return Visibility.Hidden;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public class bool2VisibilityConverter2 : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
try
|
||||
{
|
||||
if ((bool)value)
|
||||
return Visibility.Visible;
|
||||
return Visibility.Collapsed;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LOG.Write(ex);
|
||||
}
|
||||
return Visibility.Collapsed;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public class Visibility2boolConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
try
|
||||
{
|
||||
Visibility vi = (Visibility)value;
|
||||
if (vi == Visibility.Visible) return true;
|
||||
return false;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LOG.Write(ex);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
try
|
||||
{
|
||||
bool isChecked = (bool)value;
|
||||
if (isChecked) return Visibility.Visible;
|
||||
return Visibility.Hidden;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LOG.Write(ex);
|
||||
}
|
||||
return Visibility.Visible;
|
||||
}
|
||||
}
|
||||
|
||||
public class RolloverDataTimeConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
DateTime dt;
|
||||
var isSucc = DateTime.TryParse(value.ToString(), out dt);
|
||||
if (isSucc)
|
||||
return string.Format("{0}{1}{2}", " 【", dt.ToString("yyyy/MM/dd HH:mm:ss"), "】 ");
|
||||
}
|
||||
return "N/A";
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public class BoolToValueConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value == null) return null;
|
||||
|
||||
return ((bool)value) ? parameter : DependencyProperty.UnsetValue;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value == null) return null;
|
||||
return object.Equals(value, parameter);
|
||||
}
|
||||
}
|
||||
public class RadioBoolToIntConverter : IValueConverter
|
||||
{
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
|
||||
int integer = (int)value;
|
||||
|
||||
if (integer == int.Parse(parameter.ToString()))
|
||||
|
||||
return true;
|
||||
|
||||
else
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
|
||||
return parameter;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class FlowConverterForWeiQiMultiBinding : IMultiValueConverter
|
||||
{
|
||||
#region IMultiValueConverter 成员
|
||||
|
||||
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
string str_Result = string.Empty;
|
||||
bool isOpen = false;
|
||||
for (int i = 0; i < values.Length; i++)
|
||||
{
|
||||
bool.TryParse(values.GetValue(i) + "", out isOpen);
|
||||
if (isOpen == false)
|
||||
return isOpen;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 其中有一项为true就是true
|
||||
/// </summary>
|
||||
public class FlowConverterForAllTrueMultiBinding : IMultiValueConverter
|
||||
{
|
||||
#region IMultiValueConverter 成员
|
||||
|
||||
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
string str_Result = string.Empty;
|
||||
bool isOpen = false;
|
||||
for (int i = 0; i < values.Length; i++)
|
||||
{
|
||||
bool.TryParse(values.GetValue(i) + "", out isOpen);
|
||||
if (isOpen == true)
|
||||
return isOpen;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 第一项false则关闭,后面的只要有true就打开
|
||||
/// </summary>
|
||||
public class FlowConverterFirstFalseMultiBinding : IMultiValueConverter
|
||||
{
|
||||
#region IMultiValueConverter 成员
|
||||
|
||||
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
if (values.Length < 2) return false;
|
||||
|
||||
bool isOpen = false;
|
||||
bool.TryParse(values.GetValue(0) + "", out isOpen);
|
||||
|
||||
if (!isOpen) return false;
|
||||
|
||||
isOpen = false;
|
||||
for (int i = 1; i < values.Length; i++)
|
||||
{
|
||||
bool.TryParse(values.GetValue(i) + "", out isOpen);
|
||||
if (isOpen == true)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
using MECF.Framework.Common.Account;
|
||||
using MECF.Framework.Common.Account.Permissions;
|
||||
|
||||
namespace MECF.Framework.UI.Core.Converters
|
||||
{
|
||||
public class IntPermissionToIsEnabledConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is int intPerm && Enum.IsDefined(typeof(MenuPermissionEnum), intPerm))
|
||||
{
|
||||
var perm = (MenuPermissionEnum)intPerm;
|
||||
return perm == MenuPermissionEnum.MP_READ_WRITE;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
// /************************************************************************
|
||||
// * @file MarkDownToHtmlConverter.cs
|
||||
// * @author Su Liang
|
||||
// * @date 2023/04/14
|
||||
// *
|
||||
// * @copyright © Sicentury Inc.
|
||||
// *
|
||||
// * @brief
|
||||
// *
|
||||
// * @details
|
||||
// *
|
||||
// *
|
||||
// * *****************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace MECF.Framework.UI.Core.Converters
|
||||
{
|
||||
public class MarkdownToHtmlConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is string mdText)
|
||||
{
|
||||
var conv = new MarkdownDeep.Markdown();
|
||||
var html = conv.Transform(mdText);
|
||||
var sb = new StringBuilder();
|
||||
sb.Append(
|
||||
"<!DOCTYPE html><html lang=\"en\">" +
|
||||
"<head> " +
|
||||
" <meta charset=\"UTF-8\" />" +
|
||||
" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" /> " +
|
||||
" <title>Sic 系统更新历史记录</title> " +
|
||||
" <style> " +
|
||||
" .mainContainer { font-family: Tahoma, Verdana, sans-serif; margin: 10px;} " +
|
||||
" </style>" +
|
||||
" </head><body oncontextmenu=\"return false;\"> " +
|
||||
" <div class=mainContainer> ");
|
||||
sb.Append(html);
|
||||
sb.Append("<div>" +
|
||||
"</body>" +
|
||||
"</html>");
|
||||
return sb.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
return "<h1>Content is not Markdown text<h1>";
|
||||
}
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace MECF.Framework.UI.Core.Converters
|
||||
{
|
||||
public class NullToVisibilityConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return value == null ? Visibility.Collapsed : Visibility.Visible;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Data;
|
||||
using Aitex.Core.RT.Log;
|
||||
|
||||
namespace Aitex.Core.UI.Converters
|
||||
{
|
||||
public class RolloverDataPointerInfoConverter : IMultiValueConverter
|
||||
{
|
||||
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
try
|
||||
{
|
||||
DateTime time = (DateTime)values[0];
|
||||
double y = (double)values[1];
|
||||
|
||||
return string.Format("【{0}】 {1}", time.ToString("yyyy/MM/dd HH:mm:ss"), y);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LOG.Write(ex);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Data;
|
||||
using System.Windows;
|
||||
|
||||
namespace Aitex.Core.UI.Converters
|
||||
{
|
||||
public class ServiceModeConvert : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
bool vInOnOff = false;
|
||||
|
||||
if (value != null)
|
||||
{
|
||||
bool.TryParse(value + "", out vInOnOff);
|
||||
}
|
||||
|
||||
return vInOnOff ? Visibility.Visible : Visibility.Collapsed;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetTypes, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Media;
|
||||
using Aitex.Core.RT.Log;
|
||||
|
||||
namespace MECF.Framework.UI.Core.Converters;
|
||||
|
||||
public class StringToColorConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is string str)
|
||||
{
|
||||
const string pattern = @"^#([A-Fa-f0-9]{8})$";
|
||||
return Regex.IsMatch(str, pattern)
|
||||
? ColorConverter.ConvertFromString(str) // convert string to color
|
||||
: Colors.Transparent; // miss match pattern
|
||||
}
|
||||
|
||||
return Colors.Transparent; // not a string
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if(value is Color color)
|
||||
return $"#{color.A:X2}{color.R:X2}{color.G:X2}{color.B:X2}";
|
||||
else
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace MECF.Framework.UI.Core.Converters
|
||||
{
|
||||
public class StringToDoubleConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value == null)
|
||||
return double.NaN;
|
||||
|
||||
if (double.TryParse(value.ToString(), out var dbl))
|
||||
return dbl;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value == null)
|
||||
return "";
|
||||
return value.ToString() ?? "";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Data;
|
||||
using System.Windows;
|
||||
using Aitex.Core.UI.ControlDataContext;
|
||||
|
||||
namespace Aitex.Core.UI.Converters
|
||||
{
|
||||
public class ValveVisibleConvert : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
bool vInOnOff = false;
|
||||
|
||||
if (value != null)
|
||||
{
|
||||
bool.TryParse((value as GasValveDataItem).Feedback + "", out vInOnOff);
|
||||
}
|
||||
|
||||
return vInOnOff ? Visibility.Visible : Visibility.Collapsed;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetTypes, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace Aitex.Core.Util
|
||||
{
|
||||
/// <summary>
|
||||
/// 其中有一项为true就是true
|
||||
/// </summary>
|
||||
public class FlowConverterForAllTrueMultiBinding : IMultiValueConverter
|
||||
{
|
||||
#region IMultiValueConverter 成员
|
||||
|
||||
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
string str_Result = string.Empty;
|
||||
bool isOpen = false;
|
||||
for (int i = 0; i < values.Length; i++)
|
||||
{
|
||||
bool.TryParse(values.GetValue(i) + "", out isOpen);
|
||||
if (isOpen == true)
|
||||
return isOpen;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace Aitex.Core.UI.Converters
|
||||
{
|
||||
public class WidthMoreConvertor : IValueConverter
|
||||
{
|
||||
#region IValueConverter Members
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
decimal ret = 0;
|
||||
Decimal.TryParse(value + "", out ret);
|
||||
ret += 30;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user