6
我的DataGrid
中的一列包含中的Hyperlink
。當選中一行時,超鏈接顯示爲藍色,因此我想將它的文本顏色更改爲白色。我怎樣才能做到這一點?在TextBlock內建立超鏈接
的DataGrid
看起來是這樣的:
<DataGrid>
<DataGrid.Columns>
<DataGridTemplateColumn Header="Title">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock TextWrapping="Wrap">
<Hyperlink NavigateUri="{Binding Url}">
<Run Text="{Binding Title}" />
</Hyperlink>
</TextBlock>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
我已經試過
<Style TargetType="DataGridCell">
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="TextBlock.Foreground" Value="White" />
</Trigger>
</Style.Triggers>
</Style>
與TextElement
代替TextBlock
相同的代碼。兩者都適用於其他列,但不適用於超鏈接。
這使得超鏈接正確的色彩選擇時,也使得黑色未選中時,我不希望出現這種情況。 – svick 2010-08-03 21:38:58
擴展您的款式以符合您的要求 – HCL 2010-08-03 22:21:28
嘿,那不會發生在我身上。是的,現在有用,謝謝。不過,我仍然很好奇是否有更好的方法來做到這一點。 – svick 2010-08-03 22:49:08