简体   繁体   English

从BackGroundWorker创建/访问画笔

[英]Create/Access Brush from a BackGroundWorker

The second fails as cannot create (new) a UI object in a background thread 第二个失败,因为无法在后台线程中创建(新)UI对象
(well you can create it but you can't use it) (您可以创建它,但不能使用它)
Error message: 错误信息:
Cannot use a DependencyObject that belongs to a different thread than its parent Freezable. 无法使用与其父级Freezable属于不同线程的DependencyObject。

docTextAndHighlight.WordHighlight.Add(wordPos, new HightLight(w.Len, System.Windows.Media.Brushes.Salmon));


docTextAndHighlight.WordHighlight.Add(wordPos, new HightLight(w.Len, new SolidColorBrush((Color)ColorConverter.ConvertFromString(w.Highlight))));

These colors all start System.Windows.Media.Brushes 这些颜色全部启动System.Windows.Media.Brushes

Adding a feature to let the user save the search so need to persist the color to the database. 添加一项功能以使用户保存搜索,因此需要将颜色保留到数据库中。
Right now I am using ToString to save the Hex color 现在我正在使用ToString保存十六进制颜色
The problem with that is the New 问题是新的
Is there way to serialize a System.Windows.Media.Brush such that I don't have to new it when I unserialize? 有没有办法序列化System.Windows.Media.Brush,这样我在反序列化时就不必更新它了?

I only use like 8 brushes so I as thinking of putting them in an Enum and serialize by Enum index. 我只使用了8个画笔,因此我想将它们放在Enum中并按Enum索引进行序列化。

创建画笔后,在其上调用“ Freeze ,该画笔不再是线程固定的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM