【问题标题】:Custom path border自定义路径边框
【发布时间】:2019-05-20 01:14:36
【问题描述】:

我想创建一个边框,它也将覆盖我的<Path> caret 对象。

这是我现在拥有的:

这是我想要的样子:

我尝试使用 Path stroke 和一些 hacky StrokeDashArray 值,但是结果并不令人满意,而且看起来也不对。

整个网格周围实现包含Path的边框的其他方法是什么?

这是我当前的 XAML 代码:

   <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <Path
            x:Name="Caret"
            Grid.Row="0"
            Margin="0,0,15,-1"
            HorizontalAlignment="Right"
            Panel.ZIndex="1"
            Data="M0 10 L 20 10 L 10 0 Z"
            Fill="White" />

        <Border
            Grid.Row="1"
            Padding="10"
            Background="White"
            BorderBrush="Teal"
            BorderThickness="1"
            CornerRadius="15">
        </Border>
    </Grid>

【问题讨论】:

  • 您可以考虑自定义 Shape,即从 Shape 派生的类,它覆盖 DefiningGeometry 属性和 OnRenderSizeChanged 方法。

标签: c# wpf path border


【解决方案1】:

您将需要修改您的路径数据并在您的路径中添加描边以实现您正在寻找的内容。试试这个代码。

 <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <Path x:Name="Caret"
              Grid.Row="0"
              Margin="0,0,15,-1"
              HorizontalAlignment="Right"
              Panel.ZIndex="1"
              Data="M0 10  L 10 0 L 20 10"
              Stroke="Teal"
              Fill="White" 
              ClipToBounds="True"
              />

        <Border Grid.Row="1"
                Padding="10"
                Background="White"
                BorderBrush="Teal"
                BorderThickness="1"
                CornerRadius="15">
        </Border>
    </Grid>

【讨论】:

  • 就像我说的,我已经尝试过这种方法,但不幸的是,this is not accurate
  • 您可以使用 ClipToBounds 属性来避免这种行为。尝试更新的答案。
  • 这样就可以了,但是顶角is also being clipped
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-26
  • 2020-12-10
  • 2016-02-09
  • 1970-01-01
  • 1970-01-01
  • 2015-12-28
相关资源
最近更新 更多