From bd07d1b7e3f6114d11efb774fdf21ff732a64ef9 Mon Sep 17 00:00:00 2001 From: NaBian <836904362@qq.com> Date: Wed, 12 Dec 2018 10:25:22 +0800 Subject: [PATCH] add two converters --- HandyControl/HandyControl.csproj | 2 ++ HandyControl/Themes/Basic/Converters.xaml | 2 ++ .../Tools/Converter/Boolean2StrConverter.cs | 32 +++++++++++++++++ .../Tools/Converter/Int2StrConverter.cs | 35 +++++++++++++++++++ 4 files changed, 71 insertions(+) create mode 100644 HandyControl/Tools/Converter/Boolean2StrConverter.cs create mode 100644 HandyControl/Tools/Converter/Int2StrConverter.cs diff --git a/HandyControl/HandyControl.csproj b/HandyControl/HandyControl.csproj index 60c9cd5a..c0f135f5 100644 --- a/HandyControl/HandyControl.csproj +++ b/HandyControl/HandyControl.csproj @@ -106,6 +106,8 @@ + + diff --git a/HandyControl/Themes/Basic/Converters.xaml b/HandyControl/Themes/Basic/Converters.xaml index a4ae0c09..8a4d418f 100644 --- a/HandyControl/Themes/Basic/Converters.xaml +++ b/HandyControl/Themes/Basic/Converters.xaml @@ -13,5 +13,7 @@ + + \ No newline at end of file diff --git a/HandyControl/Tools/Converter/Boolean2StrConverter.cs b/HandyControl/Tools/Converter/Boolean2StrConverter.cs new file mode 100644 index 00000000..21d30e01 --- /dev/null +++ b/HandyControl/Tools/Converter/Boolean2StrConverter.cs @@ -0,0 +1,32 @@ +using System; +using System.Globalization; +using System.Windows.Data; + +namespace HandyControl.Tools.Converter +{ + public class Boolean2StrConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is bool boolValue) + { + if (parameter is string str) + { + var arr = str.Split(';'); + if (arr.Length > 1) + { + return boolValue ? arr[1] : arr[0]; + } + return ""; + } + return ""; + } + return ""; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/HandyControl/Tools/Converter/Int2StrConverter.cs b/HandyControl/Tools/Converter/Int2StrConverter.cs new file mode 100644 index 00000000..3ebfff45 --- /dev/null +++ b/HandyControl/Tools/Converter/Int2StrConverter.cs @@ -0,0 +1,35 @@ +using System; +using System.Globalization; +using System.Windows.Data; + +namespace HandyControl.Tools.Converter +{ + public class Int2StrConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is int intValue) + { + if (parameter is string str) + { + var arr = str.Split(';'); + if (arr.Length > intValue) + { + return arr[intValue]; + } + + return intValue; + } + + return intValue; + } + + return value; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file