D
D
Dmitry Bashinsky2017-09-26 19:54:34
WPF
Dmitry Bashinsky, 2017-09-26 19:54:34

How to change the color of a static resource?

Hello! Straight to the point.
I have such a resource (icon)

<Grid x:Key="Kubok" >
            <Viewbox>
                <Grid>
                    <Path Fill="Red" Data="M497,60c-1.113,0-80.425,0-80.425,0l3-30H436c8.284,0,15-6.716,15-15s-6.716-15-15-15H76c-8.284,0-15,6.716-15,15    s6.716,15,15,15h16.425l3,30c0,0-79.367,0-80.425,0C6.716,60,0,66.716,0,75v32.883c0,36.566,12.608,72.653,35.502,101.614    c22.77,28.804,54.903,49.565,90.479,58.459l11.917,2.979c18.386,24.499,43.899,42.704,73.102,52.045V391h-15    c-24.813,0-45,20.187-45,45v46h-15c-8.284,0-15,6.716-15,15s6.716,15,15,15h240c8.284,0,15-6.716,15-15s-6.716-15-15-15h-15v-46    c0-24.813-20.187-45-45-45h-15v-68.018c24.684-7.896,46.927-22.175,64.546-41.667l29.492-9.18    c33.899-10.551,63.045-31.18,84.289-59.657C500.702,183.825,512,149.976,512,114.59V75C512,66.716,505.284,60,497,60z M30,107.883    V89.9h68.425l10.709,107.188c1.273,12.729,4.173,25.109,8.558,36.883C65.337,214.13,30,164.362,30,107.883z M316,421    c8.271,0,15,6.729,15,15v46H181v-46c0-8.271,6.729-15,15-15H316z M241,391v-61.769c4.961,0.504,9.966,0.769,15,0.769    s10.039-0.265,15-0.769V391H241z M373.015,194.103C366.991,254.346,316.78,300,256,300c-60.83,0-110.995-45.699-117.015-105.897    c-0.489-4.889-16.142-161.515-16.41-164.203h266.85C389.153,32.618,373.497,189.279,373.015,194.103z M482,114.59    c0,56.587-37.114,108.165-90.881,127.235c6.185-14.072,10.187-29.143,11.747-44.736L413.575,89.9H482V114.59z" />
                    <Path Fill="Red" Data="M335.907,119.269l-45.92-6.672l-20.536-41.611c-2.527-5.12-7.742-8.361-13.451-8.361s-10.924,3.242-13.451,8.361    l-20.536,41.611l-45.92,6.672c-12.276,1.784-17.202,16.92-8.313,25.585l33.228,32.389l-7.844,45.734    c-2.097,12.226,10.776,21.59,21.764,15.813L256,217.197l41.072,21.592c10.968,5.767,23.867-3.552,21.764-15.813l-7.844-45.734    l33.228-32.389C353.102,136.195,348.192,121.054,335.907,119.269z M284.405,161.265c-3.535,3.446-5.148,8.411-4.314,13.277    l4.039,23.551l-21.15-11.119c-4.368-2.297-9.591-2.298-13.96,0l-21.15,11.119l4.039-23.551c0.834-4.866-0.779-9.831-4.314-13.277    l-17.11-16.679l23.646-3.436c4.885-0.71,9.109-3.779,11.294-8.206L256,111.518l10.575,21.427    c2.185,4.427,6.409,7.496,11.294,8.206l23.646,3.436L284.405,161.265z" />
                </Grid>
            </Viewbox>
        </Grid>

I use it in my program like this:
<ContentControl Content="{StaticResource Kubok}" Margin="5" Width="30" />

Everything works, but for example, I need to change the color of this icon, for this I have to change the Fill in the resource, there is an option to accumulate these icons with different colors, but this is not sooo at all, and that's why I'm looking for how I can at the "top level " set the color of this icon? what would be something like this:
<ContentControl Content="{StaticResource Kubok}" Margin="5" Width="30" Color="Red"/>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Peter, 2017-09-26
@BashkaMen

And what Style did not please? Something like this:

<ContentControl Content="{StaticResource Kubok}" Style="{StaticResource  KubokStyle}" Margin="5" Width="30" />

<Style key="KubokStyle" TargetType="ContentControl">
  <Style.Resources>
      <Style TargetType="Path">
          <Setter Property="Fill" Value="Red" /> 
      </Style>
  </Style.Resources>
</Style>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question