Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6926983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:59:21+00:00 2026-05-27T10:59:21+00:00

How can I programmatically highlight a DataGrid cell in Silverlight?

  • 0

How can I programmatically highlight a DataGrid cell in Silverlight?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:59:21+00:00Added an answer on May 27, 2026 at 10:59 am

    You’ll need to do the following:

    1. Add a property (let’s name it IsSelectedInChart) to your data item class. This property must be public and must raise the INotifyPropertyChanged.PropertyChanged event whenever its value changes.
    2. In your lineseries_SelectionChanged you should find the data item that corresponds to the selected point and set IsSelectedInChart to true for it and to false for others.
    3. Make all instances of DataGridRow that exist in the DataGrid have a Binding set to their Background property with Path=IsSelectedInChart and a custom `IValueConverter’.

    The converter should look like this:

    public class ValueConverter : IValueConverter
    {
      public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
      {
        // TODO: be more careful with nulls and non-expected values
        bool isSelected = (bool)value;
        return isSelected ? new SolidColorBrush(Colors.Red) : DependencyProperty.UnsetValue;
      }
    }
    

    The last step is the trickiest. It may be implemented by overriding the DataGridRow Style. One approach is shown in https://stackoverflow.com/a/4268159/795861, another one in https://stackoverflow.com/a/3542179/795861. Check those out.

    All these steps are required since you’re likely to have a lot of rows in the DataGrid. It uses UI virtualization which makes it impossible to simple set the Background property on the required DataGridRow because a single row object is used to present multiple data items. Thus, the only way to make it work with scrolling is binding the background to the data items.

    UPDATE

    To highlight cells in a column that is known at design time, set DataGridColumn.CellStyle property to that column definition instead of setting the row style:

    <sdk:DataGrid>
      <sdk:DataGrid.Columns>
        <sdk:DataGridTextColumn x:Name="theColumnToHighlight">
          <sdk:DataGridTextColumn.CellStyle>
            <Style TargetType="{x:Type sdk:DataGridCell}">
              <Setter Property="local:SetterValueBindingHelper.PropertyBinding">
                <Setter.Value>
                  <local:SetterValueBindingHelper
                      Type="System.Windows.Controls.Control, System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e"
                      Property="Background"
                      Binding="{Binding IsSelectedInChart, Converter={StaticResource highlighterConverter}}"/>
                </Setter.Value>
              </Setter>
            </Style>
          </sdk:DataGridTextColumn.CellStyle>
        </sdk:DataGridTextColumn>
      </sdk:DataGrid.Columns>
    </sdk:DataGrid>
    

    Should work, although I haven’t tried. The xaml does the same as I’ve suggested for highlighting entire rows, but applies it to cells in a specific column.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can programmatically check which version of the WMI (Windows Management Instrumentation) is installed
I know you can programmatically determine the tranparency color of a .gif Is there
Is there any way that I can programmatically create (and I guess access) hidden
Does anyone know if you can programmatically save a report shown in a reportviewer
Is there a way I can programmatically count the number of links for a
How can I programmatically make a query in MS Access default to landscape when
How can I programmatically determine if I have access to a server (TCP) with
How can I programmatically lock/unlock, or otherwise prevent/enable editing, a source file on Linux
How can you programmatically tell an HTML select to drop down (for example, due
How can I programmatically change my browser's default home page with C#?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.