wpf datagrid 圆角
时间: 2023-08-30 14:10:42 浏览: 84
要在 WPF DataGrid 中添加圆角,可以在 DataGrid 标记内部添加 Border 标记,并将 CornerRadius 属性设置为所需的值。例如:
```xml
<DataGrid>
<Border CornerRadius="10" Background="White">
<DataGrid.Columns>
<!-- 列定义 -->
</DataGrid.Columns>
</Border>
</DataGrid>
```
这将创建一个具有圆角边框的 DataGrid。如果要更改 DataGrid 行的圆角,可以使用 RowStyle 属性来自定义行的样式。例如:
```xml
<DataGrid RowStyle="{StaticResource RoundedRowStyle}">
<DataGrid.Columns>
<!-- 列定义 -->
</DataGrid.Columns>
</DataGrid>
```
然后在资源中定义 RoundedRowStyle 样式:
```xml
<Style x:Key="RoundedRowStyle" TargetType="{x:Type DataGridRow}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridRow}">
<Border CornerRadius="10" Background="{TemplateBinding Background}">
<DataGridCellsPresenter ItemsPanel="{TemplateBinding ItemsControl.ItemsPanel}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
```
这将覆盖 DataGrid 行的默认样式,并将其包装在具有圆角边框的 Border 中。