diff --git a/src/Common/ChartDrawing/Converter/StringToColorConverter.cs b/src/Common/ChartDrawing/Converter/StringToColorConverter.cs new file mode 100644 index 000000000..c018f4615 --- /dev/null +++ b/src/Common/ChartDrawing/Converter/StringToColorConverter.cs @@ -0,0 +1,29 @@ +using System; +using System.Globalization; +using System.Windows.Data; +using System.Windows.Media; + +namespace CompMs.Graphics.Converter +{ + [ValueConversion(typeof(string), typeof(Color))] + public sealed class StringToColorConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { + if (value is Color color) { + return color.ToString(); + } + return Binding.DoNothing; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { + if (value is string text) { + try { + return ColorConverter.ConvertFromString(text); + } + catch (FormatException) { + } + } + return Binding.DoNothing; + } + } +} diff --git a/src/MSDIAL5/MsdialGuiApp/View/Setting/FileClassSetView.xaml b/src/MSDIAL5/MsdialGuiApp/View/Setting/FileClassSetView.xaml index b666dfeb2..0f7e84092 100644 --- a/src/MSDIAL5/MsdialGuiApp/View/Setting/FileClassSetView.xaml +++ b/src/MSDIAL5/MsdialGuiApp/View/Setting/FileClassSetView.xaml @@ -3,6 +3,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:converter="clr-namespace:CompMs.Graphics.Converter;assembly=ChartDrawing" xmlns:ui="clr-namespace:CompMs.Graphics.UI;assembly=ChartDrawing" xmlns:behavior="clr-namespace:CompMs.Graphics.Behavior;assembly=ChartDrawing" xmlns:vm="clr-namespace:CompMs.App.Msdial.ViewModel.Setting" @@ -11,6 +12,7 @@ d:Background="White" d:DesignHeight="450" d:DesignWidth="400"> +