<Style TargetType="{x:Type DataGrid}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGrid}">
<!-- extra attributes as example, but you can tweak whatever you want in the template, what is important is the "CornerRadius" here -->
<Border Name="Border"
Padding="{TemplateBinding Padding}"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="1"
CornerRadius="3">
<ScrollViewer Name="DG_ScrollViewer" Focusable="false" CanContentScroll="True" IsDeferredScrollingEnabled="true">
<!-- here you can also overwrite the Scrollviewer's Template if you wish -->
<ItemsPresenter SnapsToDevicePixels="True" />
</ScrollViewer>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
2条答案
按热度按时间z18hc3ub1#
你必须覆盖datagrid的模板(听起来比实际要复杂得多):
这个样式应该放在/theme/Generic.xaml或者你的app.xaml中(或者你想要的任何xaml字典中,只要它被正确引用)
nmpmafwu2#
我已经找到了解决方案。我已经采取了默认的数据网格模板,并把ItemsPresenter到边界与所需的参数。然后我把这个模板应用到数据网格。