我有一个带有自定义模板的自定义按钮。在模板中,我使用网格定义对 aRectangle
和.Canvas
Label
这是模板:
<ControlTemplate
TargetType="{x:Type l:UXButton}">
<Border
Name="TEMP_Container"
Padding="{TemplateBinding Padding}"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}"
FlowDirection="{Binding Converter={StaticResource LocalizedFlowConverter}}">
<Grid
Name="TEMP_ContentContainer"
Background="Blue">
<Grid.ColumnDefinitions>
<ColumnDefinition
Name="ColumnIcon"
Width="{Binding ActualHeight, RelativeSource={RelativeSource AncestorType={x:Type Border}}}" />
<ColumnDefinition
Name="ColumnSpace"
Width="auto" />
<ColumnDefinition
Name="ColumnContent"
Width="auto" />
</Grid.ColumnDefinitions>
<Rectangle
Name="TEMP_Icon"
Grid.Column="0"
Margin="0"
Fill="{TemplateBinding Foreground}">
<Rectangle.OpacityMask>
<VisualBrush
Stretch="{Binding RelativeSource={RelativeSource AncestorType=l:UXButton}, Path=Stretch}"
Visual="{Binding RelativeSource={RelativeSource AncestorType=l:UXButton}, Path=IconSource}" />
</Rectangle.OpacityMask>
</Rectangle>
<Canvas
Name="TEMP_Space"
Grid.Column="1"
Margin="0"
Width="{TemplateBinding Spacing}" />
<Label
Name="TEMP_Content"
Grid.Column="2"
Margin="0"
Padding="0"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
Foreground="{TemplateBinding Foreground}">
<TextBlock
Margin="0"
Padding="0"
Text="{TemplateBinding Content}"
TextDecorations="{TemplateBinding TextDecorations}" />
</Label>
</Grid>
</Border>
</ControlTemplate>
结果如下:
Canvas
正如您所看到的,网格在(红色)和(绿色)之间留下了一个额外的空间(蓝色)Rectangle
,我似乎无法理解为什么!我什至尝试使用静态值作为列宽,但没有帮助。我也使用了XAML debugging tools
,它似乎是Grid
.
这个空间是从哪里来的?