Frage

I want to load a WPF element from an external file. Example I have a file brush.xaml like this:

<SolidColorBrush>Black</SolidColorBrush>

And I want to load this brush in my code:

using(FileStream stream = new FileStream("brush.xaml"))
  Brush myBrush = XamlReader.Load(stream) as Brush;

How can I do?

War es hilfreich?

Lösung

Your code is right, but in the xaml file use:

<SolidColorBrush xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
   #FF0000
</SolidColorBrush>

With the hexadecimal format. Anyway, if you have any doubt, you can make a test using XamlWriter.

Andere Tipps

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top