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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:21:11+00:00 2026-06-12T06:21:11+00:00

Background: I have a DataGrid whose ItemSource is bound to an ObservableCollection<Dictionary<string, object>> type.

  • 0

Background:

I have a DataGrid whose ItemSource is bound to an ObservableCollection<Dictionary<string, object>> type. The thought behind this is to allow the DataGrid to display a bunch of objects from different sources (This is a log gathering program so the fields all vary from one type of log to the next). I have taken care of the generation of columns through a behavior so I have no knowledge of what the columns will be until runtime.

The Problem:

I want to have a way to show commonalities between the entries based off a field (column) while maintaining the sort order from a different column. To do this I was thinking of going with a color coding system. If the value in a cellA under columnA matched the value of cellB in columnA, the two rows that the cells belong to would get the same unique color for the values found in both cells. The user should also be able to change the column to color code.

I’ve been trying to work with a style to get the desired effect but am having some troubles. Here’s the code in question.

MainWindow.xaml

<DataGrid...>
   <DataGrid.CellStyle>
      <Style TargetType="DataGridCell">
         <Setter Property="Background">
            <Setter.Value>
               <MultiBinding Converter="{StaticResource RowBackgroundConverter}">
                  <MultiBinding.Bindings>
                     <Binding RelativeSource="{RelativeSource Self}"/>
                     <Binding Path="ColumnName"/>
                     <Binding Path="."/>
                  </MultiBinding.Bindings>
               </MultiBinding>
            </Setter.Value>
         </Setter>
      </Style>
   </DataGrid.CellStyle>
</DataGrid>

RowBackgroundConverter

/// <summary>
/// A converter that changes the background of a DataGrid based on a cell value
/// </summary>
public class RowBackgroundConverter : IMultiValueConverter
{

    public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        if (values[0] is DataGridCell)
        {
            DataGridCell cell= (DataGridCell)values[0];
            string columnName = (string)values[1];
            Dictionary<string, object> dataGridValues = (Dictionary<string, object>)values[2];

            // Check the cell's column name and compare it against the desired column name (columnName) Get the index of the value and get the mapped brush. (dataGridValues[columnName]) 

            return new SolidColorBrush(ColorMap.ColorDictionary[0]);

        }

        return SystemColors.AppWorkspaceColor;
    }

    public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

And in my ViewModel I have a ColumnName property for the desired column to color code.

The problem is how can I reach a property in my view model when my multibinding’s context is the data grid cell?

  • 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-12T06:21:12+00:00Added an answer on June 12, 2026 at 6:21 am

    In case I understand your question correctly, you should be able to get to the ColumnName property by setting the relativesource of the binding to the Window.

    This assumes that the DataContext of the Window has been set to the ViewModel that contains the ColumnName property.

    Something like this should work:

    {Binding Path=DataContext.ColumnName, 
             RelativeSource={RelativeSource AncestorType=Window}}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dataGrid bound to a List object and this works fine by
I have a datagrid bound to an ObservableCollection, and what I'd like to do
I have an ObservableCollection bound to a WPFToolkit DataGrid in an MVVM pattern. Every
I have an ObservableCollection bound to a DataGrid and everything works fine. I want
I have a DataGrid that needs to show a gradient background on mouseover of
BackGround: I have an advanced data grid. The data provider for this ADG is
Background: I have an MVC based polaroid object. The model keeps the photo's metadata,
Background I have a function that takes a config object as an argument. Within
Background: I have this with rollup query defined in MySQL: SELECT case TRIM(company) when
Background I'm trying to bind my objects to a DataGrid I have a list

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.