【问题标题】:Inverted Corner Radius in WPF (something like a negative Radius)WPF 中的倒角半径(类似于负半径)
【发布时间】:2011-12-01 01:20:29
【问题描述】:

我尝试创建一个负角半径的边框,如下所示:

我想要内侧的半径。这可以通过内置函数实现还是我必须用路径绘制它?

【问题讨论】:

    标签: c# .net wpf visual-studio wpf-controls


    【解决方案1】:

    好吧,我遇到了同样的问题并试图找出解决方案。 最后但并非最不重要的一点是,我得出的结论是,使用border 无法解决此问题。

    我专注于使用PathCombinedGeometry 函数绘制我的Border

    如果有人仍在寻找如何制作倒圆角的解决方案,这是我的解决方案:

    <Grid>
                <Path Stroke="Black" Fill="White" StrokeThickness="10" Stretch="Fill">
                    <Path.Data>
                        <CombinedGeometry GeometryCombineMode="Exclude">
                            <CombinedGeometry.Geometry1>                                
                                <RectangleGeometry Rect="100,200 200,100"/>
                            </CombinedGeometry.Geometry1>
                            <CombinedGeometry.Geometry2>
                                <EllipseGeometry RadiusX="50" RadiusY="50" Center="300,300" />
                            </CombinedGeometry.Geometry2>
                        </CombinedGeometry>
                    </Path.Data>
                </Path>
        <Button Margin="10" Height="10" Width="10"/>
    </Grid>
    

    您可以通过更改RectangleGeometry Rect="100,200 200,100 中的值来调整Rectangle 的大小,并在其中添加任何其他WPF 项。在这种情况下,我添加了Button

    结果如下:

    【讨论】:

      【解决方案2】:

      您可以在Border 中使用Border

      <Border Background="Black">
          <Border Margin="10" Background="White" CornerRadius="20">
              <!-- ... -->    
          </Border>
      </Border>
      

      【讨论】:

      • 这不是我想要的,图片显示了完整的边框,它最终应该看起来。
      • 好吧,这似乎不是最优雅的解决方案,但它确实有效。我现在使用两个边框。它们没有相互融合,但都很好地放置在一个网格中。
      • 这确实回答并没有解决原来的问题。 @Tokk 如果您使用边框内的边框解决了原始问题,请分享您是如何做到的。
      猜你喜欢
      • 1970-01-01
      • 2015-06-03
      • 2021-06-16
      • 2012-08-27
      • 1970-01-01
      • 1970-01-01
      • 2016-03-28
      • 2022-01-14
      • 1970-01-01
      相关资源
      最近更新 更多