我正在探索在我的WPF應用程序中使用專業設計的矢量圖像作爲ControlTemplates的想法。這個想法是製作幾種類型的控件,每種都有不同的視覺設計,然後可以拖放它們。這與視覺設計師(a'la visio)完全相同的用例WPF:在WPF中使用設計的矢量圖像作爲控件模板
我有以下XAML。它定義了一個帶有目標類型Button的控件模板,並且我有一個使用此模板的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>
其中在d的d XML命名空間:LayoutOverrides =「寬度,高度」是從哪裏來的? – 2009-07-24 20:28:26