有没有办法在WPF数据网格中的水平网格线上有虚线?我到处搜索,似乎无法找到具体的做法。可以解决这个问题的一个解决方案是设置Datagrid.RowStyle。我已经试过这个,它会导致错误。我已将我的数据网格绑定到数据表。 2栏只是文字,第3栏是图像栏。对于这个列,我使用了DataGridTemplateColumn。文本块和图像。我希望你能帮助我......如果你想在我的代码示例是这样的。WPF DataGrid中的虚线水平网格线
<StackPanel>
<dg:DataGrid Name="questionList"
HeadersVisibility="None"
AutoGenerateColumns="False"
Background="White"
Margin="42,32,43,0"
BorderThickness="0"
GridLinesVisibility="Horizontal"
CanUserAddRows="False"
HorizontalGridLinesBrush="#FFCCCCCC"
MaxHeight="549"
Cursor="Hand"
PreviewMouseLeftButtonUp="questionnaireList_PreviewMouseLeftButtonUp">
<dg:DataGrid.CellStyle>
<Style TargetType="{x:Type dg:DataGridCell}">
<Setter Property="BorderThickness" Value="0"/>
</Style>
</dg:DataGrid.CellStyle>
<dg:DataGrid.RowStyle>
<Style TargetType="{x:Type dg:DataGridRow}">
<Setter Property="Background" Value="{Binding MyImage, Converter={x:Static my:StatusColorConverter.instance}}" />
</Style>
</dg:DataGrid.RowStyle>
<dg:DataGrid.Columns>
<dg:DataGridTemplateColumn Width="69*">
<dg:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Margin="12,16,0,17"
FontSize="18"
Foreground="#0891F1"
Text="{Binding Path=Number}"
TextWrapping="Wrap"/>
</DataTemplate>
</dg:DataGridTemplateColumn.CellTemplate>
</dg:DataGridTemplateColumn>
<dg:DataGridTemplateColumn Width="601*">
<dg:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock FontSize="16" Foreground="#666666"
Text="{Binding Path=Desc}"
TextWrapping="Wrap"
TextAlignment="Justify"
Margin="0,16,0,17" />
</DataTemplate>
</dg:DataGridTemplateColumn.CellTemplate>
</dg:DataGridTemplateColumn>
<dg:DataGridTemplateColumn Width="117*">
<dg:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Image Source="{Binding Path=Imgs}"
Stretch="None"
VerticalAlignment="Top"
HorizontalAlignment="Right"
Margin="0,16,18,17" />
</DataTemplate>
</dg:DataGridTemplateColumn.CellTemplate>
</dg:DataGridTemplateColumn>
</dg:DataGrid.Columns>
</dg:DataGrid>
</StackPanel>
我用尽你的示例代码,但它似乎有一个与“转换器有问题= {x:Static dg:DataGrid.RowDetailsScrollingConverter}“。该错误表示DataGrid没有静态成员“RowDetailsScrollingConverter”。我使用WPFToolkit,因为我使用.net 3.5和visual studio 2008.我也检查了MSDN并确认DataGrid有一个静态成员“RowDetailsScrollingConverter”。我错过了什么? – patlimosnero
更新我的答案与'模板'的3.5工具包'DataGrid' –
虽然这可能工作,他们有一个原因是在代码中绘制的原因。我建议你在使用这种方法之前,先在网格中测试一些重要的数据量 - 无论是否使用定制线。如果您改为“DataGridCell”的子类并在那里渲染行,则可能会看到更好的性能。 –