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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:33:34+00:00 2026-05-31T08:33:34+00:00

My app as it initiates it populates a DataGrid with data retrieved from a

  • 0

My app as it initiates it populates a DataGrid with data retrieved from a Data Base. My fields are: Name, ID and Status. The first two no problem, but the third one (Status) is an int, either 1 or 0, indicating active or inactive.

I decided to create an User Control to show the “Status” field. It’s nothing more than a circle wich turns green or red depending on the value of “Status”. The default color of the control is red.

I also created a list object(“data”) that contains my information plus the control with it’s respective color. So far no problem. Everything works, and if I do a quick watch on my data object, everything is as it should be.

My problem is that after I populate the DataGrid with “myDataGrid.ItemsSource = data”, every control “Status” appears as red, when some of them should be green. If I breakpoint at any given time and quick watch my “data” object, everything is fine, but the DataGrid does not update.
The same happens for sorting. If I change the color of any of the controls, after sorting any of the columns, it resets the color of all my user controls to it’s default (red).

After a few tests and research I think that the problem is that the DataGrid updates itself at the end of the item source and instanciates new User Controls instead of using the ones on my data object.

Is there anyway to solve this? I’ve tried a few solutions that I’ve found around the web and nothing worked so far!

  • 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-31T08:33:35+00:00Added an answer on May 31, 2026 at 8:33 am

    Lets assume your class looks something like this…

     public class MyObject
     {
         public string Name { get; set; }
         public int ID { get; set; }
         public int Status { get; set; }
         public UserControl StatusControl { get; }
     }
    

    Is my assumptions correct?

    If so, I have a few recommendations

    1. Implement INotifyPropertyChanged event and raise property chnaged notifications for Name, ID and Status properties.
    2. Get rid of your UserControl type (i.e. StatusControl) property from your model (i.e. MyObject class)
    3. Do not use AutogenerateColumns as true (which is by default true) on the datagrid. Create your specific columns…

       <tk:DataGrid x:Name="MyDataGrid"
                    ItemsSource="{Binding MyObjects}"
                    AutoGenerateColumns="False">
            <tk:DataGrid.Columns>
                <tk:DataGridTextColumn Header="ID"
                                       Binding="{Binding ID}" />
                <tk:DataGridTextColumn Header="Name"
                                       Binding="{Binding Name}" />
                <tk:DataGridTemplateColumn Header="Status"
                                           SortMemberPath="Status">
                    <tk:DataGridTemplateColumn.CellTemplate>
                      <DataTemplate>
                          <ns:StatusControl>
                              <ns:StatusControl.Style>
                                  <Style TargetType="{x:Type ns:StatusControl}">
                                      <Setter Property="IndicatorColor"
                                              Value="Green"/>
                                      <Style.Triggers>
                                          <DataTrigger Binding="{Binding Status}"
                                                       Value="1">
                                              <Setter Property="IndicatorColor"
                                                      Value="Red"/>
                                          </DataTrigger>
                                      </Style.Triggers>
                                  </Style>                                           
                              </myNamespace:StatusControl.Style>
                          </myNamespace:StatusControl>
                      </DataTemplate>
                  </tk:DataGridTemplateColumn.CellTemplate>
              </tk:DataGridTemplateColumn>
          </tk:DataGrid.Columns>
       <tk:DataGrid>
      

    Here your user control (like the StatusControl) should expose a Brush property (something like IndicatorColor) so that based on the Status, the Fill color of the Circle in the user control (see the DataTrigger) will change.

    So this way as you receive updates on Status property of MyObject the DataTrigger will update the color on the user control.

    Hope this helps…

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

Sidebar

Related Questions

How do I initiate a Windows XP user Log Off from a C# app?
An app I'm writing always crashes on a clients computer, but I don't get
My app uses a WebRequest at certain points to get pages from itself. This
I have an iOS app that displays content from a sqlite db in a
I'm having difficulty with a Flex app I'm creating. I believe the problem is
My app has a language setting feature. Now it works perfectly, but after I
My iPhone app initiates a phone call with: NSURL *phoneURL = [NSURL URLWithString:[NSString stringWithFormat:@tel://%@,
I am using a netNamedPipeBinding to perform inter-process WCF communication from a windows app
I have an app based on Apple's PageControl sample. The first time the view
I have UITableViewController (initiated by the Navigation-based app project template). I am overriding loadView

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.