Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 序列化梯度刷_C#_Wpf_Serialization_Brush - Fatal编程技术网

C# 序列化梯度刷

C# 序列化梯度刷,c#,wpf,serialization,brush,C#,Wpf,Serialization,Brush,我试图使用序列化保存笔刷对象,但出现以下错误: 程序集“PresentationCore,版本=4.0.0.0,区域性=中性,PublicKeyToken=31bf3856ad364e35”中的类型“System.Windows.Media.LinearGradientBrush”未标记为可序列化 如何将笔刷对象保存到文件中?试试这个 var brush = new LinearGradientBrush(new GradientStopCollection( new GradientS

我试图使用序列化保存笔刷对象,但出现以下错误:

程序集“PresentationCore,版本=4.0.0.0,区域性=中性,PublicKeyToken=31bf3856ad364e35”中的类型“System.Windows.Media.LinearGradientBrush”未标记为可序列化

如何将笔刷对象保存到文件中?

试试这个

var brush = new LinearGradientBrush(new GradientStopCollection(
    new GradientStop[] { new GradientStop(Colors.Blue, 2.0), new GradientStop(Colors.Red, 3.0) }));

using (var outfile = File.CreateText("Brush.xaml"))
{
    XamlWriter.Save(brush, outfile);
}
这将产生以下结果:

<LinearGradientBrush xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
    <LinearGradientBrush.GradientStops>
        <GradientStop Color="#FF0000FF" Offset="2" />
        <GradientStop Color="#FFFF0000" Offset="3" />
    </LinearGradientBrush.GradientStops>
</LinearGradientBrush>


您所说的“将笔刷对象保存到对象”是什么意思?请解释您试图实现的目标,而不是您试图实现的目标。与其将笔刷对象保存到文件中,为什么不保存其值?我想保存我的应用程序的外观设置。我无法保存值,因为它们太多了。