DataGridHyperlinkColumn text color when highlighted

css grid background-color
wpf grid background
wpf set grid background color in code

I have a simple WPF application which displays reddit links in a DataGrid:

Notice however that the link in the DataGridHyperlinkColumn isn't visible when a row is selected, due to the color of the link and the color of the row highlight.

What's a good way to resolve this? Change the link text color? Change the row highlight color?

If possible, please show your suggestion in terms of C# code as opposed to XAML as this application isn't using XAML. Otherwise, a XAML solution is fine; I'll just convert it to C#. :-)

For reference, here's the code used for the Title column:

var event_setter = new EventSetter()
{
    Event = Hyperlink.ClickEvent,
    Handler = (RoutedEventHandler)((sender, e) => 
    {
        System.Diagnostics.Process.Start((data_grid.SelectedItem as Link).Url);
    })
};

var style = new Style();

style.Setters.Add(event_setter);

var hyperlink_column = new DataGridHyperlinkColumn()
{
    Header = "Title",
    Binding = new Binding("Title"),
    ElementStyle = style,
    Width = 600
};

data_grid.Columns.Add(hyperlink_column);

You could add an implicit Hyperlink style to your DataGrid:

const string Xaml = "<Style TargetType=\"Hyperlink\" xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\">" +
                    "<Style.Triggers>" +
                    "<DataTrigger Binding=\"{Binding IsSelected, RelativeSource={RelativeSource AncestorType=DataGridCell}}\" Value=\"True\">" +
                    "<Setter Property=\"Foreground\" Value=\"White\" />" +
                    "</DataTrigger>" +
                    "</Style.Triggers>" +
                    "</Style>";
data_grid.Resources.Add(typeof(Hyperlink), System.Windows.Markup.XamlReader.Parse(Xaml) as Style);
data_grid.Columns.Add(hyperlink_column);

How to change the styling of the link in a DatagridHyperlinkColumn, By default the selected cell background is blue and the hyperlink foreground but I havent even managed to get the default hyperlink colour to change. The Foreground of the text in the DataGridHyperlinkColumn cannot be� If your browser supports the <mark> tag, "highlighted text" should have a yellow background. Example code Here is an example of <mark>highlighted text</mark> using the &lt;mark&gt; tag. Example result. Here is an example of highlighted text using the <mark> tag. Highlight text with only HTML code

The Selector.IsSelected property of DataGridHyperLink Column can be used and when the selection on particular item changes you can update the style with trigger.

<DataGridHyperlinkColumn.CellStyle>
    <Style TargetType="{x:Type Hyperlink}">
        <Setter Property="Foreground" Value="Blue"/>
        <Style.Triggers>
            <Trigger Property="Selector.IsSelected" Value="True">
                <Trigger.Setters>
                    <!--change the value for the property based on your needs-->
                    <Setter Property="Foreground" Value="Yellow"/>
                </Trigger.Setters>
            </Trigger> 
        </Style.Triggers>
    </Style>
 </DataGridHyperlinkColumn.CellStyle>

c#, To change the grid's foreground and background color so that it appears Run the application and observe that the grid now appears green with white text in the grid header. Highlight an item in the grid and notice the mouse hover style did not change; you Overview � Members � DataGridHyperlinkColumn Constructor. I have a simple WPF application which displays reddit links in a DataGrid:. Notice however that the link in the DataGridHyperlinkColumn isn't visible when a row is selected, due to the color of the link and the color of the row highlight.

Here's a version of the answer provided by @mm8 converted from XAML to C#:

var data_trigger = new DataTrigger()
{
    Binding = new Binding()
    {
        Path = new PropertyPath("IsSelected"),
        RelativeSource = new RelativeSource() { AncestorType = typeof(DataGridCell) }
    },
    Value = true
};

data_trigger.Setters.Add(new Setter(ForegroundProperty, new SolidColorBrush(Colors.White)));

var style = new Style(typeof(Hyperlink));

style.Triggers.Add(data_trigger);

data_grid.Resources.Add(typeof(Hyperlink), style);

Changing the Grid's Background and Foreground Color, or a WPF DataGrid with a DataGridHyperlinkColumn, using . Notice that when a row is highlighted, cells containing static text show Perhaps the link text and its underline could become the same color as the static text� The new color will be applied to various windows including system apps and dialogs like the Run box, Wordpad (the selected document text), Notepad, File Explorer, Local Group Policy Editor, and more. Default colors: A custom highlighted text color: Here is how to change it. To Change Highlighted Text Color in Windows 10, Open the Registry

Here's a version of the answer provided by @mm8 converted from XAML to C# which uses some extension methods to avoid intermediate variables:

data_grid.Resources.Add(
    typeof(Hyperlink),
    new Style(typeof(Hyperlink))
    .AddTrigger(
        new DataTrigger()
        {
            Binding = new Binding()
            {
                Path = new PropertyPath("IsSelected"),
                RelativeSource = new RelativeSource() { AncestorType = typeof(DataGridCell) }
            },
            Value = true
        }
        .AddSetter(new Setter(ForegroundProperty, new SolidColorBrush(Colors.White)))));

android – 突出顯示DataGridHyperlinkColumn文字顏色時, The standard styling options show the hyperlink in a different colour and with an DataGridHyperlinkColumn Binding = "{Binding MoreInfoUri}" Header In some cases you will want to use different text in the column, whilst� To enable highlighting colors with underline blocks go to Tools > Color Highlighter > Color Highlighters > Highlight colors in all text > Highlight colors with blocks and choose one of To the right of the color, To the left of the color, Below the color. These are options are self-explanatory.

Pure XAML solution:

<DataGrid>
    <DataGrid.Resources>
        <Style TargetType="{x:Type Hyperlink}">
            <Style.Triggers>
                <DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource AncestorType=DataGridCell}}"
                             Value="True">
                    <DataTrigger.Setters>
                        <Setter Property="Foreground" Value="Yellow"/>
                    </DataTrigger.Setters>
                </DataTrigger> 
            </Style.Triggers>
        </Style>
    </DataGrid.Resources>

    <DataGrid.Columns>
        <DataGridHyperlinkColumn Width="180"
                                 Header="Url"
                                 Binding="{Binding Path=Uri, Mode=OneWay}" />
    </DataGrid.Columns>

</DataGrid>

強調表示時のDataGridHyperlinkColumnテキストの色, Wpf datagrid header text color. T could be a pre WPF Datagrid Change the Color of Selected Row Customize line How adjust and One useful feature of a DataGrid is its DataGridHyperlinkColumn, in which each cell is a hyperlink to a URL. datagridhyperlinkcolumn set text . Archived Forums > Windows Presentation Foundation (WPF) Windows Presentation Foundation (WPF) https://social.msdn.microsoft.com

WinForms and WPF links in data grid cells become practically , Examples. The following example shows a DataGridHyperlinkColumn that sets the Uri with the Binding property and the hyperlink text with the ContentBinding property. The Hyperlink.Click event is handled automatically because NavigationWindow is the parent of the DataGrid.

WPF Data Display Controls - DataGrid, Highlighted text looks fine on the screen, but when I print, the highlighted color is much to dark. Is there a way to decrease the density of the color, or choose from a larger color palette? This thread is locked.

Wpf datagrid header text color, Text highlighting in PowerPoint for Microsoft 365 and PowerPoint 2019 lets subscribers mark text in yellow or another highlighter color. (This feature is available on both Windows and macOS, and it's available in your browser in PowerPoint for the web.)

Comments
  • can please post the XAML code for datagrid too
  • I've added an answer based on yours which demonstrates the same approach but converted from XAML to C#.
  • It's not the Hyperlink that is selected. It's the row in the DataGrid which means that binding to Selector.IsSelected won't solve the issue.