我正在尝试序列化/反序列化“渐变画笔”属性
RuntimeTypeModel.Default.Add(typeof(System.Windows.Media.Brush), true).AddSubType(101, typeof(System.Windows.Media.SolidColorBrush));
RuntimeTypeModel.Default.Add(typeof(System.Windows.Media.Brush), true).AddSubType(102, typeof(System.Windows.Media.ImageBrush));
RuntimeTypeModel.Default.Add(typeof(System.Windows.Media.Brush), true).AddSubType(103, typeof(System.Windows.Media.LinearGradientBrush));
RuntimeTypeModel.Default.Add(typeof(System.Windows.Media.Brush), true).AddSubType(104, typeof(System.Windows.Media.RadialGradientBrush));
RuntimeTypeModel.Default.Add(typeof(System.Windows.Media.Brush), true).AddSubType(105, typeof(System.Windows.Media.GradientBrush));
RuntimeTypeModel.Default.Add(typeof(SolidColorBrush), false).Add("Color");
RuntimeTypeModel.Default.Add(typeof(Color), false).Add("A", "R", "G", "B");
LinearGradientBrush myLinearGradientBrush = new LinearGradientBrush();
myLinearGradientBrush.StartPoint = new Point(0, 0);
myLinearGradientBrush.EndPoint = new Point(1, 1);
myLinearGradientBrush.GradientStops.Add(new GradientStop(Colors.Yellow, 0.0));
myLinearGradientBrush.GradientStops.Add(new GradientStop(Colors.Red, 0.25));
myLinearGradientBrush.GradientStops.Add(new GradientStop(Colors.Blue, 0.75));
myLinearGradientBrush.GradientStops.Add(new GradientStop(Colors.LimeGreen,1.0));
brush = myLinearGradientBrush;
using (var file1 = File.Create(@"C:\Users\vitor\Desktop\test.bin"))
{
Serializer.Serialize(file1, brush);
}
GradientBrush newBrush;
using (var file1 = File.OpenRead(@"C:\Users\vitor\Desktop\test.bin"))
{
newBrush = Serializer.Deserialize<GradientBrush>(file1);
}
但是当我反序列化newBrush.GradientStops为空时。如何对GradientBrush进行序列化/反序列化?