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!