您不希望使用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>