Add the Canvas
and Path
作为页面上或 App.xaml 或其他任何地方的资源,请记住设置x:Key
。然后使用一个ContentControl
来引用资源。
<!-- In Resources, either on the Page or App.xaml for app-wide reuse -->
<Canvas x:Key="TickCanvas" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Name="appbar_check" Width="76" Height="76" Clip="F1 M 0,0L 76,0L 76,76L 0,76L 0,0">
<Path Width="37.9998" Height="31.6665" Canvas.Left="19.0001" Canvas.Top="22.1668" Stretch="Fill" Fill="#FF000000" Data="F1 M 23.7501,33.25L 34.8334,44.3333L 52.2499,22.1668L 56.9999,26.9168L 34.8334,53.8333L 19.0001,38L 23.7501,33.25 Z "/>
</Canvas
<!-- On your page, or somewhere -->
<ViewBox>
<ContentControl Content="{StaticResource TickCanvas}" />
</ViewBox>
作为它有效的证明,我能够看到它的勾选!
顺便说一句,我经常只获取路径数据、迷你标记并将其保存为字符串资源。然后使用Path
我通过引用标记资源Data={StaticResource TickPath}
这样我就可以使用Height
and Width
on the Path
本身或通过设置让它由其父级扩展和收缩Stretch="Uniform"
。节省了开销Viewbox
.
<!-- In App.xaml for app-wide reuse -->
<x:String x:Key="TickPath">F1 M 23.7501,33.25L 34.8334,44.3333L 52.2499,22.1668L 56.9999,26.9168L 34.8334,53.8333L 19.0001,38L 23.7501,33.25 Z </x:String>
<!-- On page, template or wherever -->
<Path Data="{StaticResource TickPath} />
此技术在这种情况下可能不起作用,因为那里有一个剪辑几何体。但对于简单的矢量来说,它很好,我将手绘字体(不能作为字体嵌入)作为标记存储在文件中,然后在运行时加载它们 -Data={Binding PathData}
同样有效。