开发者

Styling Hyperlink inside a TextBlock

One of the columns in my DataGrid contains a Hyperlink in a TextBlock. When a row is selected, the hyperlink shows as blue on blue, so i want to change it's text color to white. How can I do that?

The DataGrid looks like this:

<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>

I've tried

<Style TargetType="DataGridCell">
    <Style.Triggers>
        <Trigger Property="IsSelected" Value="True">
            <Setter Property="TextBlock.Foreground" Value="White" />
        </Trigger>
    </Style.Triggers>
</Style>

and the same code with开发者_Python百科 TextElement instead of TextBlock. Both work for other columns, but not for this one with hyperlink.


Use the following declaration for the link:

<Run Text="{Binding Title}" 
     Foreground="{Binding 
         RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataGridCell},
                                        Path=Foreground}"/> 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜