在app.xaml中定义SVG图标

时间:2016-11-21 08:17:30

标签: c# wpf xaml svg

我想在全球范围内定义我的svg图标,我可以在每个文件中使用它们。这就是我决定将它们放入app.xaml文件的原因。

在此文件中我定义了图标

<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>

,现在我可以写任何.xaml文件

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

获得此结果

img

我现在的问题是,我想更改.xaml文件中图像的大小或颜色。那可能吗?如果是的话,你能给我一点解释吗?

1 个答案:

答案 0 :(得分:1)

仅将几何体声明为资源,例如

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

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

并使用它,如下所示,您可以在其中设置显式大小并填充画笔:

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