我在Expression Design中绘制了一个16x16矢量,我将其导入Blend并用于控制模板。这是XAML:
<ControlTemplate x:Key="CircularButtonTemplate" TargetType="{x:Type Button}">
<Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Name="Layer_1" Width="16" Height="16" Canvas.Left="0" Canvas.Top="0">
<Ellipse x:Name="_circle" Width="15.0208" Height="15.0208" Canvas.Left="0.375033" Canvas.Top="0.479169" Stretch="Fill" Fill="#FF666666" />
<Path x:Name="_darkShadow" Width="14.727" Height="14.686" Canvas.Left="0.232" Canvas.Top="0.357" StrokeThickness="3" StrokeLineJoin="Round" Stroke="Black" Data="M 2.02083,8.03473L 13.7501,8.03473M 7.84484,2.14584L 7.84484,13.8333"/>
<Path x:Name="_lightShadow" Width="14.727" Height="14.686" Canvas.Left="0.857" Canvas.Top="0.732" StrokeThickness="3" StrokeLineJoin="Round" Stroke="#FFABABAB" Data="M 2.02083,8.03473L 13.7501,8.03473M 7.84484,2.14584L 7.84484,13.8333"/>
<Path x:Name="_plus" Width="14.7292" Height="14.6875" Canvas.Left="0.520833" Canvas.Top="0.645836" StrokeThickness="3" StrokeLineJoin="Round" Stroke="#FFFFFFFF" Data="M 2.02083,8.03473L 13.7501,8.03473M 7.84484,2.14584L 7.84484,13.8333"/>
</Canvas>
虽然Blend和Exp Design可以整齐地显示图像,但在运行时,应用于按钮时,中心的+号无法正确对齐:
我该如何解决这个问题?
答案 0 :(得分:2)
尝试在画布上设置UseLayoutRounding =“True”。
答案 1 :(得分:1)
只需要调整生成的代码,它就可以提供更多定义的值。试试这个。
<Canvas x:Name="Layer_1" Width="16" Height="16" VerticalAlignment="Center" HorizontalAlignment="Center">
<Ellipse x:Name="_circle" Width="16" Height="16" Stretch="Fill" Fill="#FF666666" HorizontalAlignment="Center" VerticalAlignment="Center" />
<Path x:Name="_darkShadow" Width="16" Height="16" StrokeThickness="3" Stroke="Black" Data="M 2.02083,8.03473L 13.7501,8.03473M 7.84484,2.14584L 7.84484,13.8333" HorizontalAlignment="Center" VerticalAlignment="Center" UseLayoutRounding="False" Canvas.Left="-0.5" Canvas.Top="-0.5"/>
<Path x:Name="_lightShadow" Width="16" Height="16" StrokeThickness="3" Stroke="#FFABABAB" Data="M 2.02083,8.03473L 13.7501,8.03473M 7.84484,2.14584L 7.84484,13.8333" Canvas.Left="-0.5" Canvas.Top="-0.5" Visibility="Collapsed"/>
<Path x:Name="_plus" Width="14" Height="14" StrokeThickness="3" Stroke="#FFFFFFFF" Data="M 2.02083,8.03473L 13.7501,8.03473M 7.84484,2.14584L 7.84484,13.8333" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Canvas>