有沒有辦法在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」的子類並在那裏渲染行,則可能會看到更好的性能。 –