A
A
AlexSofar2019-07-03 04:37:54
WPF
AlexSofar, 2019-07-03 04:37:54

Why can't I set the color of the GeometryDrawing.Brush brush, is it throwing an exception?

public void LoadIcon(object obj)
{
    DrawingBrush brush = obj as DrawingBrush;
    DrawingGroup dgroup = brush.Drawing as DrawingGroup;    
    foreach (var item in dgroup.Children)
    {
        var geometry = item as GeometryDrawing;
        // Это часть вызывает исключение
        geometry.Brush = new SolidColorBrush(Color.FromArgb(255, 0, 0, 0));   
    };                
    IconButton = brush;
}

I need to change the color of a brush, but when I try to assign a color, the environment throws an exception.
5d1c0315c0046526666338.jpeg
Although the property is not a read-only property:
5d1c04151dbb4552797726.jpeg
Some sort of contradiction*?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman, 2019-07-03
@AlexSofar

Your GeometryDrawing (most likely DrawingGroup and DrawingBrush too) are in a "frozen" state. In this state, nothing can be changed in them, and they work more efficiently. You can check this by looking at the value of the IsFrozen property . It's best to remove their freezing, but if that's problematic, you can make an editable copy of the DrawingBrush with the Clone method .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question