Domanda

The second fails as cannot create (new) a UI object in a background thread
(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.

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

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
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?

I only use like 8 brushes so I as thinking of putting them in an Enum and serialize by Enum index.

È stato utile?

Soluzione

Call Freeze on the brush after you create it and it is no longer thread-affinitized.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top