Changing DrawingImage brush binded to DynamicResource

106 Views Asked by At

I have a DrawingImage object as a resource which uses brush color from DynamicResource like this:

<DrawingImage x:Key="img_building">
    <DrawingImage.Drawing>
        <DrawingGroup ClipGeometry="M0,0 V512 H512 V0 H0 Z">
            <DrawingGroup Opacity="1">
                <GeometryDrawing Geometry="F1 M512,512z M0,0z M256.5,17.2L512,119.4 512,153.8 477.6,153.8C477.6,158.4 475.7,162.2 472,165.9 468.3,169.6 463.6,170.5 459,170.5L53,170.5C48.4,170.5 43.7,168.6 40,165.9 36.3,163.1 34.4,158.5 34.4,153.8L0,153.8 0,119.4 256.5,17.2z M68.8,188.2L136.6,188.2 136.6,392.6 171,392.6 171,188.2 238.8,188.2 238.8,392.6 273.2,392.6 273.2,188.2 341,188.2 341,392.6 375.4,392.6 375.4,188.2 443.2,188.2 443.2,392.6 459,392.6C463.6,392.6 468.3,394.5 472,397.2 475.7,400 477.6,404.6 477.6,409.3L477.6,426 35.3,426 35.3,409.3C35.3,404.7 37.2,400.9 40.9,397.2 44.6,393.5 49.3,392.6 53.9,392.6L69.7,392.6 69.7,188.2 68.8,188.2z M493.4,443.7C498,443.7 502.7,445.6 506.4,448.3 510.1,452 512,455.7 512,460.4L512,494.8 0.9,494.8 0.9,460.4C0.9,455.8 2.8,452 6.5,448.3 10.2,444.6 14.9,443.7 19.5,443.7L493.4,443.7z" >
                    <GeometryDrawing.Brush>
                        <SolidColorBrush Color="{DynamicResource Image.FillColor}" />
                    </GeometryDrawing.Brush>
                </GeometryDrawing>
            </DrawingGroup>
        </DrawingGroup>
    </DrawingImage.Drawing>
</DrawingImage>

And then I'm using this resource in a template like this:

    <DataTemplate x:Key="buildingImage">
        <WrapPanel>
            <WrapPanel.Resources>
                <Style TargetType="{x:Type Image}">
                    <Setter Property="Margin" Value="0,0,4,0"></Setter>
                    <Setter Property="MaxHeight" Value="20"></Setter>
                </Style>
            </WrapPanel.Resources>
            <Image Source="{DynamicResource img_building}" />
        </WrapPanel>
    </DataTemplate>

It's running fine but when I change the theme of my app, image remains same although the Image.FillColor changes. I guess it's rendering the image for once and then uses the same rendered resource over and over again.

How to fix this? Is there a way to force a hard reload on DrawingImage in code behind?

0

There are 0 best solutions below