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 7715799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:28:38+00:00 2026-06-01T02:28:38+00:00

I believe what I’m trying to do is simple enough, so I’m probably just

  • 0

I believe what I’m trying to do is “simple” enough, so I’m probably just missing something obvious.

In a DataGrid, I am trying to bind a CheckBox so that when it is checked, the Background color of its row will change. Every row has a CheckBox. I am basically implementing my own select-multiple-rows functionality (it’s a product requirement, don’t ask), and I have everything else working but this visual indication of a selected row.

I’ve read this question but where I lack my answer is what exactly to put as “BooleanPropertyOnObjectBoundToRow”. I’ve also looked at this question and tried messing with a RelativeSource but with no luck.

I create my grid in my code-behind, but here is my current style used for rows (which has my DataTrigger defined):

<Style x:Key="MyRowStyle" TargetType="DataGridRow">
      <Style.Triggers>
           <DataTrigger Binding="{Binding IsChecked}" Value="True">
               <Setter Property="Background" Value="Blue"/>
           </DataTrigger>
      </Style.Triggers>
</Style>

Now in my code-behind, I create my DataGridTemplateColumn and use a Factory to create my checkboxes, and here is my Binding-relevant code:

Binding checkBinding = new Binding("IsChecked");
checkBinding.Mode = BindingMode.OneWayToSource;
RelativeSource relativeSource = new RelativeSource();
relativeSource.AncestorType = typeof(DataGridRow);
relativeSource.Mode = RelativeSourceMode.FindAncestor;
checkBinding.RelativeSource = relativeSource;
factory.SetBinding(CheckBox.IsCheckedProperty, checkBinding);

What may be of interest is the fact that I set the ItemsSource of my DataGrid to a DataTable, but my CheckBox column does NOT have a corresponding column in the DataTable. I simply add the template column separately, maybe this lack of underlying storage is affecting this?

In any case if you need any more info, please let me know. Thanks!

  • 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-06-01T02:28:40+00:00Added an answer on June 1, 2026 at 2:28 am

    Here’s an example that works for me using C# classes, not a DataSet.

    Xaml

    <Page.Resources>
        <Style x:Key="RowStyle" TargetType="{x:Type DataGridRow}">
            <Style.Triggers>
                <DataTrigger Binding="{Binding IsChecked, UpdateSourceTrigger=PropertyChanged}" Value="True">
                    <Setter Property="Background" Value="Blue"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Page.Resources>
    
    <Page.DataContext>
        <Samples:DataGridRowHighlightViewModels/>
    </Page.DataContext>
    
    <Grid>
        <DataGrid ItemsSource="{Binding Items}" RowStyle="{StaticResource RowStyle}" CanUserAddRows="False" AutoGenerateColumns="False">
            <DataGrid.Columns>
                <DataGridCheckBoxColumn Header="Selected" Binding="{Binding IsChecked}"/>
                <DataGridTextColumn Header="Name" Binding="{Binding Name}"/>
            </DataGrid.Columns>
        </DataGrid>
    </Grid>
    

    C#

    public class DataGridRowHighlightViewModels
    {
        public DataGridRowHighlightViewModels()
        {
            Items = new List<DataGridRowHighlightViewModel>
                        {
                            new DataGridRowHighlightViewModel {Name = "one"},
                            new DataGridRowHighlightViewModel {Name = "two"},
                            new DataGridRowHighlightViewModel {Name = "three"},
                            new DataGridRowHighlightViewModel {Name = "four"},
                        };
        }
        public IEnumerable<DataGridRowHighlightViewModel> Items { get; set; } 
    }
    
    // ViewModelBase and Set() give INotifyPropertyChanged support (from MVVM Light)
    public class DataGridRowHighlightViewModel : ViewModelBase 
    {
        private bool _isChecked;
        public bool IsChecked
        {
            get { return _isChecked; }
            set { Set(()=>IsChecked, ref _isChecked, value); }
        }
    
        private string _name;
        public string Name
        {
            get { return _name; }
            set { Set(()=>Name, ref _name, value); }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I believe the application has some parts that target .NET, and some that don't.
I believe that Agile is nothing but another implementation of Spiral Model. I am
I believe that quantifying the productivity increase (extra working hours) is the most effective
I believe there is nothing currently available in MySQL that allows access to the
I believe it is a simple mistake but I have spent a lot of
I believe task I am trying to accomplish is fairly easy, but I have
I believe there is something weird when I have rewritten my urls. My website
I believe the answer may be quite simple but i cant find the answer
I believe this might be one of the most common problem that users faces
I believe that the main thread cannot die before the child thread. But is

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.