Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/Common/ChartDrawing/Converter/StringToColorConverter.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
5 changes: 5 additions & 0 deletions src/MSDIAL5/MsdialGuiApp/View/Setting/FileClassSetView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -11,6 +12,7 @@
d:Background="White"
d:DesignHeight="450" d:DesignWidth="400">
<UserControl.Resources>
<converter:StringToColorConverter x:Key="StringToColorConverter"/>
<Style TargetType="DataGrid">
<Setter Property="CanUserAddRows" Value="False"/>
<Setter Property="CanUserDeleteRows" Value="False"/>
Expand Down Expand Up @@ -48,6 +50,9 @@
</ui:CompositeColorPicker>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.ClipboardContentBinding>
<Binding Path="Color.Value" Converter="{StaticResource StringToColorConverter}" />
</DataGridTemplateColumn.ClipboardContentBinding>
</DataGridTemplateColumn>
<DataGridTextColumn Header="Order"
Binding="{Binding Order.Value, UpdateSourceTrigger=PropertyChanged}"
Expand Down
Loading