How to change brush color with Pen in DrawingGroup.Children tag

I am trying to change the Brush property from the following code snippet from another control, but don’t know how to get to this property.

This drawing brush is defined as Application.Resource en App.XAML

<DrawingBrush x:Key="Disp_Origin" Stretch="Uniform">
        <DrawingBrush.Drawing>
            <DrawingGroup>
                <DrawingGroup.Children>
                    <GeometryDrawing Geometry="F1 M 720.099,497.862C 778.822,493.976 837.662,492.02 896.514,492.02">
                        <GeometryDrawing.Pen>
                            <Pen Thickness="1.33333" MiterLimit="2.75" Brush="#FFA5AEB7"/>
                        </GeometryDrawing.Pen>
                    </GeometryDrawing>...

I need to get the pen brush property when another control is focused or frozen.

I don't know if this is possible

+4
source share
1 answer

Actually I found how to do this. But this requires code. The most important is the method Clone()that allows you to change the control resource, and you must install this brush resource from the code behind. And, unfortunately, the code is poorly read.

// Initializing code
// And as mentioned in comments code for restore color
DrawingBrush myBrush = ( Application.Current.Resources["Disp_Origin"] as DrawingBrush ).Clone();
testButton.Background = myBrush;

// On hover or on focus code
DrawingBrush settedBrush = testButton.Background as DrawingBrush;
( ( System.Windows.Media.GeometryDrawing )( ( ( System.Windows.Media.DrawingGroup )
   ( settedBrush.Drawing ) ).Children[0] ) ).Pen.Brush = new SolidColorBrush( Colors.Red );

, , .

+1

Source: https://habr.com/ru/post/1628832/


All Articles