MyNewName MyNewName - 13 days ago 5
C# Question

define SVG icons in app.xaml

I want to define my svg icons in a global place, where I can use them from every file. That's why I decided to place them into the

app.xaml
file.

Inside this file I defined the icon

<Viewbox x:Key="vb" Height="24px" Width="24px">
<Path Fill="Black" Data="M 8.5,2.5 C 6.6709399,2.5 5.495368,3.5753834 5,4.5625 4.8018528,4.9573466 4.6972223,5.3316316 4.625,5.65625 3.4072267,6.038687 2.5,7.163462 2.5,8.5 l 0,13 c 0,1.64497 1.3550302,3 3,3 l 7,0 c 1.321675,0 2.52006,-0.797431 3.0625,-2 l 1.875,0 c 0.540501,1.204091 1.740825,2 3.0625,2 l 7,0 c 1.64497,0 3,-1.35503 3,-3 l 0,-13 C 30.5,7.163462 29.592773,6.038687 28.375,5.65625 28.302869,5.3315162 28.198912,4.9563848 28,4.5625 27.50272,3.577788 26.3217,2.5 24.5,2.5 l -16,0 z m 0,2 16,0 c 1.1483,0 1.45853,0.422212 1.71875,0.9375 0.01116,0.022106 0.02095,0.040323 0.03125,0.0625 l -19.5,0 C 6.7601986,5.4779087 6.7702085,5.4595024 6.78125,5.4375 7.038632,4.9246166 7.3400601,4.5 8.5,4.5 Z m -3,3 22,0 c 0.56503,0 1,0.43497 1,1 l 0,13 c 0,0.56503 -0.43497,1 -1,1 l -7,0 c -0.544295,0 -1.033626,-0.332851 -1.25,-0.84375 l -1.03125,-2.75 0,-0.03125 -0.03125,-0.03125 c -0.295702,-0.693443 -0.960493,-1.15625 -1.71875,-1.15625 -0.760114,0 -1.454543,0.460563 -1.75,1.15625 l -0.03125,0.03125 0,0.0625 -0.9375,2.71875 C 13.53175,22.168816 13.044295,22.5 12.5,22.5 l -7,0 c -0.5650302,0 -1,-0.43497 -1,-1 l 0,-13 c 0,-0.56503 0.4349698,-1 1,-1 z m 5,3 c -2.197294,0 -4,1.802706 -4,4 0,2.197294 1.802706,4 4,4 2.197294,0 4,-1.802706 4,-4 0,-2.197294 -1.802706,-4 -4,-4 z m 12,0 c -2.197294,0 -4,1.802706 -4,4 0,2.197294 1.802706,4 4,4 2.197294,0 4,-1.802706 4,-4 0,-2.197294 -1.802706,-4 -4,-4 z m -12,2 c 1.116414,0 2,0.883586 2,2 0,1.116414 -0.883586,2 -2,2 -1.116414,0 -2,-0.883586 -2,-2 0,-1.116414 0.883586,-2 2,-2 z m 12,0 c 1.116414,0 2,0.883586 2,2 0,1.116414 -0.883586,2 -2,2 -1.116414,0 -2,-0.883586 -2,-2 0,-1.116414 0.883586,-2 2,-2 z m -6.03125,7.4375 0.21875,0.5625 -0.40625,0 0.1875,-0.5625 z"/>
</Viewbox>


, now I can write in any
.xaml
file

<ContentControl Content="{StaticResource vb}"/>


to get this result

img

My problem is now, that I want to change the size or the color of the image inside the
.xaml
file. Is that possible? If yes, can you give me a little explantion?

Answer

Declare only the geometry as a resource, like

<Application.Resources>
    ...
    <Geometry x:Key="icon1">M 8.5,2.5 ... z</Geometry>

    <GeometryGroup x:Key="icon2">
        <Geometry>...</Geometry>
        <Geometry>...</Geometry>
    </GeometryGroup>
    ...
</Application.Resources>

and use it like shown below, where you can set an explicit size and fill brush:

<Path Data="{StaticResource icon1}" Stretch="Uniform" Width="30" Fill="Black"/>
Comments