我正在尝试更新图表并在那里绘制一些散点。为此,我使用BackgroundWorker
类。它做的工作。但是我注意到,只要我为我的Point类添加颜色并想要不同颜色的显示点就会崩溃。为什么?任何想法?
public class ChartData
{
private readonly Brush Red = new SolidColorBrush(Colors.Red);
private readonly Brush Orange = new SolidColorBrush(Colors.Orange);
private readonly Brush Green = new SolidColorBrush(Colors.Green);
public ChartData(double x, double y)
{
this.XValue = x;
this.YValue = y;
}
public double XValue { get; set; }
public double YValue { get; set; }
public Brush Brush{ get; set;}
}
<telerik:ScatterPointSeries XValueBinding="XValue"
YValueBinding="YValue"
ItemsSource="{Binding Data}" >
<telerik:ScatterPointSeries.PointTemplate>
<DataTemplate>
<Ellipse Width="10"
Height="10"
Fill="{Binding DataItem.Brush}"/>
</DataTemplate>
</telerik:ScatterPointSeries.PointTemplate>
</telerik:ScatterPointSeries>
例外:Must create DependencySource on same Thread as the DependencyObject.
答案 0 :(得分:1)
如消息本身所述,您无法从antoher线程修改DependencySource
(添加,创建,删除)。您可以从同一个线程修改它,在您的情况下是UI线程。
作为一种出路,您可以输入modifying dependency source on UI thread dispatcher
App.Current.Dispatcher.Invoke((Action)delegate()
{
// Code here for updating Dependency Source.
});