Serialization and Deserialization:
28 May 20211 minute to read
SfChart provides the support for serializing and deserializing control. This section explains on how to serialize and deserialize SfChart.
Methods:
Method Name | Description |
---|---|
Serialize() | Serialize the control and saves as the XML file in the parent folder. |
Serialize(string filePath) | Serialize the control and saves as the XML file in the given file path. |
Serialize(Stream stream) | Serialize the control and saves as the XML file in the given stream. |
Deserialize() | Deserialize the XML file from the parent folder and returns the SfChart control object. |
Deserialize(string filePath) | Deserialize the XML file from the given file path and returns the SfChart control object. |
Deserialize(Stream stream) | Deserialize the XML file from the given stream and returns the SfChart control object. |
XAML
C#
<chart:SfChart x:Name=chart>
<chart:ColumnSeries ItemsSource="{Binding CategoricalDatas}" XBindingPath="Category" YBindingPath="Value" Palette="RedChrome"/>
</chart:SfChart>
<StackPanel>
<Button x:Name="Serialize" Content="Serialize" Height="50" Width="100" Margin="10" Click="Serialize_Click"/>
<Button x:Name="Deserialize" Content="Deserialize" Height="50" Width="100" Margin="10" Click="Deserialize_Click"/>
</StackPanel>
private void Serialize_Click(object sender, RoutedEventArgs e)
{
string filePath = @"E:/Documents/chart.xml";
chart.Serialize(filePath);
}
private void Deserialize_Click(object sender, RoutedEventArgs e)
{
string filePath = @"E:/Documents/chart.xml";
var deserializedChart = (SfChart)chart.Deserialize();
}