0

As the title suggests I'm trying to update the Palette of the telerik:RadPieChart asynchronously. I have implemented a Task which tries to check for new records at a given interval and updates the UI if there's any. Every other controls are updating correctly except the Palette of the telerik:RadPieChart. The Palette would disappear after the Task tries to update it. Here is the pie chart I'm working with.

<telerik:RadPieChart Name="PieLinearChart" Foreground="Gainsboro" FontSize="12" FontWeight="Black" Grid.Row="0" Palette="{Binding Tab.CurrentPoC.PalettePie1}" Height="50px">
    <telerik:RadPieChart.Series>
       <telerik:DoughnutSeries ShowLabels="True" InnerRadiusFactor="0.4"  ValueBinding="Sum"  ItemsSource="{Binding Tab.CurrentPoC.PieChart1, Mode=TwoWay}" />
    </telerik:RadPieChart.Series>
</telerik:RadPieChart>

The telerik:DoughnutSeries values are updating, though.

The code behind looks something like this:

public Task Init()
{
     .......
     .......
     ExchangeFile.DataUpdated += Exchange_DataUpdated;
     .......
     .......
}

//This method was called every certain interval
//and works from the background.
private void Exchange_DataUpdated()
{
     ......
     ......
     //Setting colors to the Palette
     //which didn't work in this case 
     //(works well for other situations)
     PalettePie1 = new ChartPalette();
     ChartPalette tmpPalette = new ChartPalette();

     tmpPalette.GlobalEntries.Add(new PaletteEntry(Utilities.NvarBrushUtils.GetBrush("Red")));
     tmpPalette.GlobalEntries.Add(new PaletteEntry(Utilities.NvarBrushUtils.GetBrush("Blue")));
     tmpPalette.GlobalEntries.Add(new PaletteEntry(Utilities.NvarBrushUtils.GetBrush("Yellow")));
     tmpPalette.GlobalEntries.Add(new PaletteEntry(Utilities.NvarBrushUtils.GetBrush("Green")));

     PalettePie1 = tmpPalette;
     ......
}

I also tried something like this but didn't help:

Application.Current.Dispatcher.Invoke(new Action(() => { 
......
ChartPalette tmpPalette = new ChartPalette();
tmpPalette.GlobalEntries.Add(new PaletteEntry(Utilities.NvarBrushUtils.GetBrush("Red")));
tmpPalette.GlobalEntries.Add(new PaletteEntry(Utilities.NvarBrushUtils.GetBrush("Blue")));
tmpPalette.GlobalEntries.Add(new PaletteEntry(Utilities.NvarBrushUtils.GetBrush("Yellow")));
tmpPalette.GlobalEntries.Add(new PaletteEntry(Utilities.NvarBrushUtils.GetBrush("Green")));

PalettePie1 = new ChartPalette();
PalettePie1 = tmpPalette;
......
 }));

Please help!

Trax
  • 341
  • 4
  • 17
  • The values are updating or are not updating? Also you have to implement any change of UI on the UIThread or the Main Thread, other wise those changes will not be visible – Saamer Jan 10 '20 at 22:57
  • @Saamer. Hi, Saamer. The values are updating perfectly. All the other controls are updating except the `Palette`. How do I implement for the changes of UI on the UIThread? I'm quite new with WPF or telerik. Thanks. – Trax Jan 12 '20 at 00:52
  • Could you please share your code behind C# code – Saamer Jan 12 '20 at 14:27
  • @Saamer Sorry for the delay. I have edited and included the code behind. Thanks. – Trax Jan 14 '20 at 02:53
  • Just follow the steps here: https://stackoverflow.com/questions/11625208/accessing-ui-main-thread-safely-in-wpf and place everything in your `Exchange_DataUpdated` event handler to run on the main/UI thread using `SynchronizationContext` or `Dispatcher` – Saamer Jan 14 '20 at 03:29
  • Hi @Saamer. I tried the mentioned solution but can't get it to work. I have updated the codes above. Am I doing something wrong? – Trax Jan 14 '20 at 03:51
  • What does PalettePie1 stand for or where is it being used? – Saamer Jan 14 '20 at 06:38
  • `PalettePie1` is a view model which is bound to the `telerik:RadPieChart` from the xaml. `` – Trax Jan 14 '20 at 06:47

0 Answers0