2

チャートを更新して、そこにいくつかの散布点を描画しようとしています。そのために私は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.

4

1 に答える 1

1

DependencySourceメッセージ自体に記載されているように、別のスレッドから変更 (追加、作成、削除) することはできません。あなたの場合はUIスレッドと同じスレッドから変更できます。

方法として、あなたはのコードを置くことができますmodifying dependency source on UI thread dispatcher

App.Current.Dispatcher.Invoke((Action)delegate()
            {
                // Code here for updating Dependency Source.
            });
于 2013-03-16T19:36:53.273 に答える