wpf 形式的所有东西的圆角

Rounded Corners for all thing in form wpf

我阅读了 this document,其中解释了如何在 WPF 中创建圆角。我的 xaml 是这样的:

<Border CornerRadius="50,0,50,0" Background="White" BorderBrush="#99ffc0c0" BorderThickness=".5">
  <Grid>
    <Ribbon x:Name="ribbon" HorizontalAlignment="Left" VerticalAlignment="Top" Width="524"/>
  </Grid>
</Border>

在这种情况下,我的丝带不像我的表格那样是圆形的。我能做什么?

您可以剪辑以创建圆角。如果您想将所有 4 个边都转角,可以使用简单的 RectangleGeomentry 来完成,如下所示:

<Ribbon x:Name="ribbon" HorizontalAlignment="Left"  VerticalAlignment="Top" Height="135" Width="524">
  <Ribbon.Clip>

    <RectangleGeometry RadiusX="50" RadiusY="50" Rect="0,0,524,135" />

  </Ribbon.Clip>
</Ribbon>

如果你只想做一个右上角和左下角,那就有点棘手了。您必须使用带有两个矩形的组合几何体。第一个从 0,0 开始,但在右边界之外结束。第二个从 -100,-100 开始(你必须确保它离 top/left 足够远,并在正确的坐标 624,235 处结束(向左、底部坐标添加 100)。这两个相交将创建顶部- 左、右下圆角。

<Ribbon x:Name="ribbon" HorizontalAlignment="Left"  VerticalAlignment="Top" Height="135" Width="524">
    <Ribbon.Clip>
        <CombinedGeometry GeometryCombineMode="Intersect">
            <CombinedGeometry.Geometry1>
                <RectangleGeometry RadiusX="50" RadiusY="50" Rect="0,0,600,200" />
            </CombinedGeometry.Geometry1>
            <CombinedGeometry.Geometry2>
                <RectangleGeometry RadiusX="50" RadiusY="50" Rect="-100,-100,624,235" />
            </CombinedGeometry.Geometry2>
        </CombinedGeometry>
    </Ribbon.Clip>
</Ribbon>

此方法要求您的功能区具有预定义的大小,如果您希望控件根据屏幕动态调整,您将使用代码隐藏进行动态剪辑。

另一种方法可能是从副本更新功能区控件模板(使用 Blend)。