RadChart throws StackOverflow Exception when saving Xaml

2 posts, 0 answers
  1. Alexander
    Alexander avatar
    5 posts
    Member since:
    Dec 2015

    Posted 08 Sep Link to this post

    I am working on a project that takes some basic controls and some telerik wpf controls, places them on a canvas, and saves these for redisplay later. All of the controls are generated at runtime.

    Whenever I attempt to save the Xaml of a RadChart, after approximately 30 seconds, the XamlWriter.Save method throws a StackOverflow exception. The problem is reproducible.

    Create project referencing the .NET Framework 4.

    Telerik.Window.Controls
    Telerik.Window.Controls.Chart
    Telerik.Window.Controls.Charting
    Telerik.Window.Controls.Data
    Telerik.Window.Controls.DataVisualization
    Telerik.Window.Data

    Place the following code on a new window:

    <Canvas Name="testCanvas" Height="350" Width="525">
        <telerik:RadChart Name="testChart" Height="350" Width="525"/>
    </Canvas>

    Place this in code-behind:

    public MainWindow()
    {
        InitializeComponent();
        this.PreviewMouseDoubleClick += Window_PreviewMouseDoubleClick;
        testCanvas.Loaded += testCanvas_Loaded;
    }
    private void testCanvas_Loaded(object sender, RoutedEventArgs e)
    {
        testChart.DefaultView.ChartLegend.UseAutoGeneratedItems = true;
        Telerik.Windows.Controls.Charting.DataSeries barSeries = new Telerik.Windows.Controls.Charting.DataSeries();
        barSeries.LegendLabel = "Expenses";
        barSeries.Definition = new Telerik.Windows.Controls.Charting.BarSeriesDefinition();
        barSeries.AddRange(new List<Telerik.Windows.Controls.Charting.DataPoint> {
            new Telerik.Windows.Controls.Charting.DataPoint() { YValue = 45, XCategory = "Jan" },
            new Telerik.Windows.Controls.Charting.DataPoint() { YValue = 48, XCategory = "Feb" },
            new Telerik.Windows.Controls.Charting.DataPoint() { YValue = 53, XCategory = "Mar" },
            new Telerik.Windows.Controls.Charting.DataPoint() { YValue = 41, XCategory = "Apr" },
            new Telerik.Windows.Controls.Charting.DataPoint() { YValue = 32, XCategory = "May" },
            new Telerik.Windows.Controls.Charting.DataPoint() { YValue = 28, XCategory = "Jun" },
            new Telerik.Windows.Controls.Charting.DataPoint() { YValue = 63, XCategory = "Jul" },
            new Telerik.Windows.Controls.Charting.DataPoint() { YValue = 74, XCategory = "Aug" },
            new Telerik.Windows.Controls.Charting.DataPoint() { YValue = 77, XCategory = "Sep" },
            new Telerik.Windows.Controls.Charting.DataPoint() { YValue = 85, XCategory = "Oct" },
            new Telerik.Windows.Controls.Charting.DataPoint() { YValue = 89, XCategory = "Nov" },
            new Telerik.Windows.Controls.Charting.DataPoint() { YValue = 80, XCategory = "Dec" }
        });
        testChart.DefaultView.ChartArea.DataSeries.AddRange(new List<Telerik.Windows.Controls.Charting.DataSeries> { barSeries });
    }
     
    private void Window_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e)
    {
     
        var fileName = @"c:\temp\tester.xaml";
        using (var fs = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.Read))
        using (var xw = new XmlTextWriter(fs, System.Text.Encoding.UTF8))
        {
            xw.Formatting = Formatting.Indented;
            xw.Indentation = 4;
            xw.IndentChar = ' ';
     
            //place breakpoint here
            XamlWriter.Save(testCanvas, xw);
        }
    }

    Run project and then double-click the window. At the "XamlWriter.Save(testCanvas, xw)", a stackoverflow exception will eventually occur

    Please let me know what I can do to correct this issue.

     

    Thanks

  2. Martin
    Admin
    Martin avatar
    1101 posts

    Posted 13 Sep Link to this post

    Hello Alexander,

    Note that RadChart has many known issues and limitations. This is why we created the new RadChartView. I recommend you to try it and see if it works for you. The new charting components have better implementation and improved performance. You can learn more about this in the RadChart vs. RadChartView help article.

    I tested your code with RadCartesianChart (part of RadChartView) and the exception is not reproduced.

    Regards,
    Martin
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top