Skip to main content
A newer version of this page is available. .

ChartControl.LoadFromFile(String) Method

Loads a chart layout from the specified file.

Namespace: DevExpress.Xpf.Charts

Assembly: DevExpress.Xpf.Charts.v21.2.dll

NuGet Package: DevExpress.Wpf.Charts

Declaration

public void LoadFromFile(
    string fileName
)

Parameters

Name Type Description
fileName String

The path to the file that contains a chart layout. An exception is raised if the specified file does not exist.

Remarks

Use the LoadFromFile method to load a chart layout from the file that the ChartControl.SaveToFile method creates.

Example

The following code uses the ChartControl.SaveToFile method to save the chart layout to a file, and the ChartControl.LoadFromFile method to restore the layout from a file:

View Example

// In the Window's code-behind file.
const string LayoutSavedFormatString = "The Chart Layout saved to the '{0}' file";
const string LayoutLoadedFormatString = "The Chart Layout loaded from the '{0}' file";

private void OnSaveBarItemClick(object sender, ItemClickEventArgs e) {
    DXSaveFileDialog dialog = new DXSaveFileDialog();
    dialog.DefaultExt = "xml";
    bool? result = dialog.ShowDialog();
    if (result.HasValue && result.Value) {
        chartControl.SaveToFile(dialog.FileName);
        statusMessageItem.Content = String.Format(LayoutSavedFormatString, dialog.FileName);
    }
}

private void OnLoadBarItemClick(object sender, ItemClickEventArgs e) {
    DXOpenFileDialog dialog = new DXOpenFileDialog();
    dialog.DefaultExt = "xml";
    bool? result = dialog.ShowDialog();
    if (result.HasValue && result.Value) {
        chartControl.LoadFromFile(dialog.FileName);
        // IMPORTANT: LoadFrom... methods create new instances of chart elements to restore the Chart Control's layout.
        // You should recreate bindings if you bind UI controls to chart elements.
        CreateBindings();
        statusMessageItem.Content = String.Format(LayoutLoadedFormatString, dialog.FileName);
    }
}
See Also