简体   繁体   English

网格在列定义之间留有额外的空间

[英]Grid leaving extra space between column definitions

I have a custom button with a custom defined template. 我有一个带有自定义模板的自定义按钮。 In the template i'm using grid definitions to sort the content of a Rectangle , Canvas and Label . 在模板中,我使用网格定义对RectangleCanvasLabel的内容进行排序。

Here's the template: 这是模板:

<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>

And here's the result: 结果如下:

在此处输入图片说明

As you can see the grid is leaving an extra space (blue) between the Canvas (red) and Rectangle (green) which i can't seem to figure why! 如您所见,网格在“ Canvas (红色)和“ Rectangle (绿色)之间留有多余的空间(蓝色),我似乎无法理解为什么! I even tried using static values for the column width but it didn't help. 我什至尝试使用静态值作为列宽,但这无济于事。 I also used the XAML debugging tools and it seems to be part of the Grid . 我还使用了XAML debugging tools ,它似乎是Grid一部分。

Where is this space coming from? 这个空间从哪里来?

I think the simple way to "fix" what you have but retain that grid as you have it is wrap it in another. 我认为“修复”您所拥有的但保留该网格的简单方法是将其包装在另一个网格中。

That way it should centralise and shrink. 这样,它应该集中和缩小。 Unless you have something sets the grid's width. 除非您有设置网格宽度的东西。

It turned out to be a bug. 原来是个错误。 Cleaning up bin and obj folders and simply doing a Rebuild fixed it. 清理binobj文件夹,然后简单地执行Rebuild修复即可。 It must have been a Resource that got stuck somewhere in the middle. 它一定是卡在中间某个地方的Resource

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM