Pie chart inside a ContentControl is not displaying correctly

Attached is a simple sample code. Three pie charts are created on the main window. I would like to ask why one of the pie charts, which is placed inside a ContentControl and has its Series porperty binding, does not render properly?

Image_9627_1780641042347


Attachment: PieChartDemo_b401037e.zip

6 Replies 1 reply marked as answer

BP Baranibharathi Pandian Syncfusion Team June 8, 2026 12:44 PM UTC

Hi ufolbb,


We have validated your query with the attached sample. We suspect that the issue may be related to the sequence in which the visual tree and the template are applied. Our development team is actively investigating this further for additional validation.


For now, we recommend binding the entire chart from the ViewModel and using it within a ContentControl. This approach will make it easier to manage your business logic from the UI.


C#:

private SfChart _chart;

 

public SfChart Chart

{

    get

    {

        return _chart;

    }

    set

    {

        _chart = value;

        OnPropertyChanged();

    }

}

public MainWindowViewModel()

{

    Chart = new SfChart();

    Chart.Series = new ChartSeriesCollection

    {

        new PieSeries

        {

            ItemsSource = ChartValues,

            XBindingPath = "Name",

            YBindingPath = "Value",

            SegmentColorPath = "Color",

            EnableAnimation = true,

            Stroke = new SolidColorBrush(Colors.White),

            StrokeThickness = 1,

            ListenPropertyChange = true,

            ShowTooltip = true

        }

    };

}


XML:

<DataTemplate x:Key="ChartTemplate">

    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">

        <ContentControl Margin="10" Width="200" Height="200" Content="{Binding Chart}"/>

        <chart:SfChart Margin="10" Width="200" Height="200">

            <chart:PieSeries ShowTooltip="True"

                ItemsSource="{Binding ChartValues}"

                YBindingPath="Value" XBindingPath="Name" SegmentColorPath="Color">

        </chart:PieSeries>

        </chart:SfChart>

    </StackPanel>

</DataTemplate>

 

<Grid>

    <Grid.RowDefinitions>

        <RowDefinition Height="*" />

        <RowDefinition Height="*" />

    </Grid.RowDefinitions>

    <ContentControl Grid.Row="1"  Content="{Binding}" ContentTemplate="{StaticResource ChartTemplate}" >

    </ContentControl>

</Grid>

 


Demo:


Screenshot 2026-06-08 175638.png

Please review the above suggestion and let us know if it meets your use case. If you need any further assistance, we will be happy to help.


Regards,

Baranibharathi P.


Attachment: SyncfusionDemo_29c27f3a.zip


UF ufolbb replied to Baranibharathi Pandian June 9, 2026 09:48 AM UTC

This solution can solve the problem, but in my real project, a large amount of code and styles are implemented in XAML, and this would require changing quite a lot of code. Is there any other workaround?



DR Dhanaraj Rajendran Syncfusion Team June 10, 2026 02:11 PM UTC

Hi ufolbb,


We are currently analyzing the scenario where the series is not being rendered when added through a ContentControl, specifically when binding the Series collection from the ViewModel.

During our investigation, we identified that the BindingExpression associated with the Series property appears to be breaking unexpectedly. We are actively working to determine the root cause and understand the underlying behavior.

Our team will continue the investigation and share detailed findings within the next two business days(13/06/2026).

We appreciate your patience and understanding.

 

Regards,

Dhanaraj R.



BP Baranibharathi Pandian Syncfusion Team June 12, 2026 11:07 AM UTC

Hi ufolbb,

 

Thank you for your patience while we investigated this behavior.

 

The problem occurs due to binding timing when the chart is placed inside a ContentControl with a DataTemplate. In this case, the Series binding is not yet resolved when the dependency property callback executes, causing it to receive a null value. Because of this, an internal condition fails and the required event listener is not registered. Even though the binding resolves later, the initialization step is not retriggered, so the chart does not render correctly.

 

As a workaround, we recommend deferring the assignment of the Series property until the visual tree is fully loaded using an attached behavior.


public static class ChartSeriesBehavior

{

    public static ChartSeriesCollection GetSeriesCollection(DependencyObject obj)

    {

        return (ChartSeriesCollection)obj.GetValue(SeriesCollectionProperty);

    }

 

    public static void SetSeriesCollection(DependencyObject obj, ChartSeriesCollection value)

    {

        obj.SetValue(SeriesCollectionProperty, value);

    }

 

    public static readonly DependencyProperty SeriesCollectionProperty =

        DependencyProperty.RegisterAttached(

            "SeriesCollection",

            typeof(ChartSeriesCollection),

            typeof(ChartSeriesBehavior),

            new PropertyMetadata(null, OnSeriesCollectionChanged));

 

    private static void OnSeriesCollectionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)

    {

        if (d is SfChart chart && e.NewValue is ChartSeriesCollection seriesCollection)

        {

            chart.Series.Clear();

            foreach (var series in seriesCollection)

            {

                chart.Series.Add(series);

            }

        }

    }

}

 

<syncfusion:SfChart local:ChartSeriesBehavior.SeriesCollection="{Binding TestCollection}">

</syncfusion:SfChart>


 

This ensures the binding is resolved before the property is applied, allowing proper initialization and rendering without requiring major changes to your existing XAML structure.

 

Output:

 

 

We hope this helps. If you need further assistance, don’t hesitate to ask out.

 

Regards,

Baranibharathi P.


Attachment: SyncfusionDemo_3ece1eb6.zip

Marked as answer

UF ufolbb replied to Baranibharathi Pandian June 15, 2026 01:16 AM UTC

Thank you, this solution has been very helpful in solving my issue.



PR Preethi Rajakandham Syncfusion Team June 15, 2026 06:11 AM UTC

Hi ufolbb,

You are welcome.

We are glad that the provided response meets your requirement. Please let us know if you need further assistance. As always, we are happy to help you out.

Regards,

Preethi R


Loader.
Up arrow icon