【发布时间】:2009-07-23 19:56:54
【问题描述】:
我正在探索在我的 WPF 应用程序中使用专业设计的矢量图像作为 ControlTemplates 的想法。这个想法是制作几种类型的控件,每种控件都有不同的视觉设计,然后可以拖放。这与视觉设计师的用例完全相同(a'la visio)
我有以下 XAML。它定义了一个目标类型为 Button 的控件模板,我有一个使用此模板的 Button。我想知道的是如何修改这个模板,使它只使用按钮的高度和宽度。在我看来,模板似乎相对于按钮的左上角呈现自身(如果我移动按钮,图像会移动)但它没有考虑按钮的尺寸,因此它保持其“设计”大小不管我做什么。
<Window x:Class="Euphrosyne.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Window.Resources>
<ControlTemplate TargetType="{x:Type Button}" x:Key="PresentBox">
<Canvas Name="svg2" >
<Canvas.Resources/>
<Canvas Name="layer1">
<Path Name="path2385" Fill="#D45500" Stroke="#FF000000" StrokeThickness="1px" StrokeLineJoin="Miter" StrokeEndLineCap="Flat" Data="M 110 82.362183 A 40 30 0 1 1 39.041709 63.365048 L 70 82.362183 z"/>
<Path Name="path2387" Fill="#FF0000" Data="M 100 100 L 79.96762 89.419767 L 59.895213 99.923868 L 63.767267 77.602471 L 47.574559 61.758424 L 69.999999 58.543274 L 80.064762 38.247014 L 90.052393 58.581339 L 112.46547 61.881608 L 96.212721 77.664061 L 100 100 z"/>
<Path Name="path2389" Fill="#C83737" Data="M 100 40.000002 L 97.601178 65.149257 L 116.9586 81.382849 L 92.298963 86.872981 L 82.841672 110.29944 L 70 88.543275 L 44.797648 86.788031 L 61.520697 67.85185 L 55.402078 43.340588 L 78.579163 53.393551 L 100 40.000002 z">
<!--path-->
</Path>
</Canvas>
</Canvas>
</ControlTemplate>
</Window.Resources>
<Grid>
<Button Template="{StaticResource PresentBox}" >Hi there</Button>
</Grid>
</Window>
【问题讨论】: