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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:41:41+00:00 2026-05-25T20:41:41+00:00

I have 2 templates for DataGrid’s CellTemplate. When I change the items, it won’t

  • 0

I have 2 templates for DataGrid’s CellTemplate. When I change the items, it won’t help me select the template for me, my DisplayModeTemplateSelector won’t even be called!

What I’m wondering is if there is a way to trigger this CellTemplateSelector again when items changed? How to refresh CellTemplate in DataGrid or ListView When Content Changes

<DataGridTemplateColumn x:Name="colorRange"
                        Width="*"
                        Header="Color Range">
    <DataGridTemplateColumn.CellTemplateSelector>
        <local:DisplayModeTemplateSelector HeatMapTemplate="{StaticResource heatMapTemplate}" ThreshHoldTemplate="{StaticResource threshHoldTemplate}" />
    </DataGridTemplateColumn.CellTemplateSelector>
</DataGridTemplateColumn>

I found this blog
http://dotdotnet.blogspot.com/2008/11/refresh-celltemplate-in-listview-when.html

I think this is similar with my problem, but I really can’t understand him! Can anyone explain it?

  • 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-25T20:41:41+00:00Added an answer on May 25, 2026 at 8:41 pm

    The solution in the blog post will not work with the DataGrid control because the DataGridTemplateColumn class doesn’t belong to the Visual Tree, and even when I tried to bind it to a static class, I didn’t suceed because of strange exceptions after property changes.

    Anyway there is two possible ways to solve this problem.

    1) The easier way.

    Using the ObservableCollection class.

        var itemIndex = 0;
        var currentItem = vm.Items[itemIndex];
        //Change necessary properties
        //..
        vm.Items.Remove(currentItem);
        vm.Items.Insert(itemIndex, currentItem);      
    

    2) The more complex way.

    You can add to your item class the property which returns the object itself.

        public ItemViewModel(/*...*/)
        {
            this.SelfProperty = this;
            //...
        }
    
        public ItemViewModel SelfProperty { get; private set; }
    
        public void Update()
        {
            this.SelfProperty = null;
            this.OnPropertyChanged("SelfProperty");
            this.SelfProperty = this;
            this.OnPropertyChanged("SelfProperty");
        }
    

    After that you can use the ContentControl.ContentTemplateSelector instead of the CellTemplateSelector like this:

                <DataGridTemplateColumn Header="Color Range">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <ContentControl Content="{Binding SelfProperty}"  ContentTemplateSelector="{StaticResource mySelector}" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
    

    And when you change the property, call the Update method somehow:

      currentItem.SomeDataProperty = "some new value";
      //Or you can add this method call to the OnPropertyChanged 
      //so that it calls authomatically
      currentItem.Update(); 
    

    The reason why I’ve set a null value to the SelfProperty in the Update method first, is that the Selector will not update a template until the Content property is completely changed. If I set the same object once again – nothing will happen, but if I set a null value to it first – changes will be handled.

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

Sidebar

Related Questions

I have a DataGrid with template column, containing a checkbox: <DataGridTemplateColumn Header=Foreign key> <DataGridTemplateColumn.CellTemplate>
I have a DataGrid template column with ComboBox. When I select a value and
I have a DataGrid with 5 template columns, However when I try and add
I have a WPF toolkit DataGrid as the dropdown in a ComboBox template. <toolkit:DataGrid
I have a Silverlight DataGrid that contains a single template column which displays a
I have a bunch of templates that are used for rpc and was wondering
I have wpf datagrid with number of template columns. some of them have textbox
I have a datagrid and a template column which is bound. I don't understand
I have a DataGrid (WPF Toolkit) with a custom combobox like edit template of
I have datagrid and inside this grid have template field. I add Header text

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.