我正在尝试更新图表,并在那里绘制一些散点。为此,我使用了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.
发布于 2013-03-17 03:36:53
正如消息本身所述,您不能从antoher线程修改DependencySource(添加、创建、删除)。你可以从相同的线程修改它,在你的例子中是UI线程。
作为一种解决方法,您可以将modifying dependency source on UI thread dispatcher的代码
App.Current.Dispatcher.Invoke((Action)delegate()
{
// Code here for updating Dependency Source.
});https://stackoverflow.com/questions/15453498
复制相似问题