WPF中Border圆角被内部Grid遮挡的问题
解决WPF无标题窗口Border圆角被内容截断的问题
问题原因
当使用WindowStyle="None"和WindowChrome时,窗口布局逻辑会和Border的圆角裁剪产生冲突,内部Grid默认不受圆角约束,导致内容溢出截断了左上角、左下角、右上角的圆角,仅右下角因窗口resize的特殊处理正常显示。
可行解决方案
方案1:给Border开启裁剪(最简单有效)
直接为Border添加ClipToBounds="True"属性,强制它裁剪所有超出圆角范围的子元素内容:
<Border x:Name="WindowBorder" Background="{DynamicResource WindowBackgroundColor}" BorderBrush="Black" BorderThickness="1" CornerRadius="10" ClipToBounds="True"> <Grid> <!-- 主内容 --> </Grid> </Border>
方案2:为内部Grid添加圆角裁剪
如果需要更灵活的裁剪控制,可以给Grid设置基于圆角的裁剪区域:
<Border x:Name="WindowBorder" Background="{DynamicResource WindowBackgroundColor}" BorderBrush="Black" BorderThickness="1" CornerRadius="10"> <Grid> <Grid.Clip> <RectangleGeometry RadiusX="10" RadiusY="10" Rect="0,0,{Binding ActualWidth, RelativeSource={RelativeSource AncestorType=Grid}},{Binding ActualHeight, RelativeSource={RelativeSource AncestorType=Grid}}" /> </Grid.Clip> <!-- 主内容 --> </Grid> </Border>
方案3:调整WindowChrome属性
修改WindowChrome的GlassFrameThickness为0,消除它对窗口裁剪逻辑的干扰:
<WindowChrome.WindowChrome> <WindowChrome CaptionHeight="0" ResizeBorderThickness="5" GlassFrameThickness="0" /> </WindowChrome.WindowChrome>
内容的提问来源于stack exchange,提问作者pfinferno
相关产品推荐
相关产品推荐

