bhagya

bhagya

  • NA
  • 1
  • 0

How to avoid 'System.StackOverflowException' when saving a canvas in a xaml

Mar 8 2010 12:05 PM

I am getting the following exception when trying to save a canvas in a wpf xaml file.

An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll

The following is what I did:

I am having a canvas in a wpf window which contains a chart and some labels.

<Canvas x:Name="c1">

            <chartingToolkit:Chart x:Name="Time_Distance_Graph" Width="1292" Height="800" Canvas.Left="2" Canvas.Top="50" BorderThickness="0" xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit">

                <chartingToolkit:Chart.Resources>

                    <Style x:Key="LineDataPointStyle" TargetType="charting:LineDataPoint" xmlns:charting="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit">

                        <Setter Property="Visibility" Value="Hidden"/>

                    </Style>

                </chartingToolkit:Chart.Resources>               

                <chartingToolkit:Chart.Axes>

                    <chartingToolkit:LinearAxis Orientation="X" Maximum="48" Interval="1" Title="Time" Margin="0,20,0,0" Visibility="Hidden" Minimum="0" ShowGridLines="False" />

                    <chartingToolkit:LinearAxis Orientation="Y" Title="Distance" Maximum="35" Minimum="0" Interval="0.5" Visibility="Hidden" ShowGridLines="False" />

                </chartingToolkit:Chart.Axes>

               

                <chartingToolkit:Chart.LegendStyle>

                    <Style TargetType="Control">

                        <Setter Property="Width" Value="0"/>

                        <Setter Property="Height" Value="0"/>

                    </Style>

                </chartingToolkit:Chart.LegendStyle>

               

                <chartingToolkit:Chart.ChartAreaStyle>

                    <Style TargetType="Panel">

                        <Setter Property="Width" Value="1259"/>

                        <Setter Property="Height" Value="743"/>

                    </Style>

                </chartingToolkit:Chart.ChartAreaStyle>

            </chartingToolkit:Chart>

            <Label Canvas.Left="1095" Canvas.Top="37.5" Height="25" Width="37.5" Content="Date:" Name="lblDate"/>

            <Label ………………………/>

            <Label ………………………/>

 

            <Label ………………………/>

</Canvas>

And also from the code behind I am adding more labels and lines dynamically to the canvas according to the requirement.

When the save button is clicked.          

The following code is set to be executed.

FileStream saveFile = new FileStream(filepath, FileMode.Create);

XamlWriter.Save(c1, saveFile);

How can I get rid of the above exception?

Expecting a soon reply.

Thanks in Advance.          

 


Answers (2)