【问题标题】:WPF Path Geometry; drawing a box with a centred arrow on the topWPF路径几何;绘制一个顶部带有居中箭头的框
【发布时间】:2020-12-08 16:56:34
【问题描述】:

我正在尝试绘制一个顶部居中的“箭头”的简单框,但我似乎无法使该箭头居中(如下例所示,箭头始终向左偏移)...

这是我的 XAML(这实际上是在模板中,但我认为这不是问题)...

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="16" />
        <RowDefinition />
        <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>
    <Rectangle Grid.Row="2"
                Fill="{TemplateBinding Background}" />
    <ContentPresenter Grid.Row="2"
                        Content="{TemplateBinding Content}"
                        ContentTemplate="{TemplateBinding ContentTemplate}"
                        ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}"
                        Margin="{TemplateBinding Padding}"
                        HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                        VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
    <Path HorizontalAlignment="Center"
            Grid.Row="1"
            Fill="{TemplateBinding Background}"
            Data="M -8,0 L 0,-16 8,0" />
</Grid>

ContentPresenter 的“内容”是一个 StackPanel,可能有也可能没有 TextBlock 子级。

我做错了什么?

【问题讨论】:

    标签: .net wpf xaml pathgeometry


    【解决方案1】:

    只要StretchNone,路径的ActualWidthActualHeight(以及它的对齐方式)就不会考虑在负坐标处绘制的几何部分。

    改成

    <Path HorizontalAlignment="Center" Data="M 0,0 L 8,-16 16,0" ... />
    

    <Path HorizontalAlignment="Center" Data="M -8,0 L 0,-16 8,0"
          Stretch="Uniform" Width="16" Height="16" ... />
    

    【讨论】:

    • 我想我要再次感谢你;真的很感激 - 我不需要告诉你它当然有效!
    猜你喜欢
    • 2011-04-09
    • 2017-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-12
    • 1970-01-01
    相关资源
    最近更新 更多