您不希望使用Canvas将这些资源存储在资源字典中。几何图形的根源大概就像一个DrawingBrush(特别是如果你使用Expression Design中创建的图像),这些都是需要被添加到资源字典,像这样的项目:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<DrawingBrush x:Key="YourResourceKey">
<DrawingBrush.Drawing>
<DrawingGroup>
<!-- This can change a lot, but a typical XAML file exported from a Design image would have the geometry of the image here as a bunch of Paths or GeometryDrawings -->
</DrawingGroup>
</DrawingBrush.Drawing>
</ResourceDictionary>
我假设你知道如何获得你的应用程序中引用的这个资源字典。
要使用资源,只需将它们分配给相应的属性即可。对于形状类型的图像,可以将它们分配给类似Rectangle的Fill属性的东西(还有很多其他方法,但这很简单)。这里有一个例子:
<Button>
<Grid>
<Rectangle Fill="{StaticResource YourResourceKey}" />
</Grid>
</Button>