首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WPF UI线程

WPF UI线程
EN

Stack Overflow用户
提问于 2013-03-17 03:10:45
回答 1查看 925关注 0票数 2

我正在尝试更新图表,并在那里绘制一些散点。为此,我使用了BackgroundWorker类。它确实能工作。但我注意到,当我向Point类添加颜色并想要显示不同颜色的点时,它就崩溃了。为什么?有什么想法吗?

代码语言:javascript
复制
    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.

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-03-17 03:36:53

正如消息本身所述,您不能从antoher线程修改DependencySource(添加、创建、删除)。你可以从相同的线程修改它,在你的例子中是UI线程。

作为一种解决方法,您可以将modifying dependency source on UI thread dispatcher的代码

代码语言:javascript
复制
App.Current.Dispatcher.Invoke((Action)delegate()
            {
                // Code here for updating Dependency Source.
            });
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15453498

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档