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

  • Home
  • SEARCH
  • 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 8940521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:03:19+00:00 2026-06-15T11:03:19+00:00

I have the following xaml; <DataTemplate DataType={x:Type NameSpace:Node}> <StackPanel Orientation=Horizontal> <TextBlock Text={Binding Item.Value}/> <ContentControl

  • 0

I have the following xaml;

    <DataTemplate DataType="{x:Type NameSpace:Node}">
        <StackPanel Orientation="Horizontal">
            <TextBlock Text="{Binding Item.Value}"/>
            <ContentControl Content="{Binding Item}"/>
        </StackPanel>
    </DataTemplate>

    <DataTemplate DataType="{x:Type NameSpace:Item}">
        <TextBlock Text="{Binding Value}" />
    </DataTemplate>

When I use the Node template to display a Node object, I get two TextBlocks which both display the same value. So far so good. The problem occurs when Item changes. When the Node class fires the INotifyPropertyChanged event, the TextBlock in the Node DataTemplate updates as expected but the TextBlock in the Item DataTemplate does not update.

How can I get the Item DataTemplate to update its bindings when the Node class fires the IPropertyChanged event?

Update
It turns out the above does work for the following simple scenario;

Xaml

        <DataTemplate DataType="{x:Type DataTemplateExample:Node}">
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding Item.Value}"/>
                <ContentControl Content="{Binding Item}"/>
            </StackPanel>
        </DataTemplate>

        <DataTemplate DataType="{x:Type DataTemplateExample:Item}">
            <TextBlock Text="{Binding Value}" />
        </DataTemplate>
    </Window.Resources>

    <Grid>
        <StackPanel Orientation="Vertical">
            <ContentControl Content="{Binding MyNode}"/>
            <Button Command="{Binding ChangeMyNodeItem}">Change Item</Button>
        </StackPanel>
    </Grid>
</Window>

c#

public class MainViewModel
{
    private readonly Node myNode;
    private readonly DelegateCommand changeMyNodeItemCmd;

    public MainViewModel()
    {
        myNode = new Node {Item = new Item("a")};
        changeMyNodeItemCmd = new DelegateCommand(()=>
            myNode.Item = new Item("b"));
    }

    public Node MyNode { get { return myNode; } }

    public ICommand ChangeMyNodeItem
    {
        get { return changeMyNodeItemCmd; }
    }
}

public class Node : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

    private Item item;
    public Item Item
    {
        set
        {
            item = value;
            if (PropertyChanged != null)
                PropertyChanged(this,new PropertyChangedEventArgs("Item"));
        }
        get { return item; }
    }
}

public class Item
{
    private readonly string value;

    public Item(string value)
    {
        this.value = value;
    }

    public string Value
    {
        get { return value; }
    }
}

In my real scenario I was using proxies, and I think this is what was getting WPF confused. Item was not actually changing – it was being remapped.

Ultimately I solved the problem using a solution similar to what ShadeOfGray proposed. But I should point out that this is not necessary unless you are using proxies.

  • 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-15T11:03:20+00:00Added an answer on June 15, 2026 at 11:03 am

    From what you have posted I think you’re firing the NotifyPropertyChanged in the wrong class. Something like that should work properly in your scenario.

    Updated according to the comment:

    public class Node : INotifyPropertyChanged
    {
        private Item item;
    
        public event PropertyChangedEventHandler PropertyChanged;
    
        public Item Item
        {
            get
            {
                return item;
            }
    
            set
            {
                item = value;
    
                this.NotifyPropertyChanged("Item");
    
                if (item != null)
                {
                    item.ForcePropertyChanged("Value");
                }
            }
        }
    
        protected void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
    
    public class Item : INotifyPropertyChanged
    {
        private string itemValue;
    
        public Item()
        {
            this.Value = string.Empty;
        }
    
        public event PropertyChangedEventHandler PropertyChanged;
    
        public string Value
        {
            get
            {
                return itemValue;
            }
    
            set
            {
                itemValue = value;
    
                NotifyPropertyChanged("Value");
            }
        }
    
        public void ForcePropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    
        protected void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following xaml code in resources: <DataTemplate DataType={x:Type s:Substance}> <StackPanel Orientation=Horizontal> <TextBlock
I have the following XAML code: <DataTemplate x:Key=NewsDataTemplate> <StackPanel Width=400 Height=100 Orientation=Horizontal HorizontalAlignment=Center VerticalAlignment=Center
I have following XAML: <TextBlock HorizontalAlignment=Center VerticalAlignment=Center FontSize=10 FontFamily=Arial Foreground=#414141> <Run Text={Binding LoadsCount} />
I have the following XAML code: <ListBox ItemsSource={Binding Languages}> <ListBox.ItemTemplate> <DataTemplate> <StackPanel> <Image Source={Binding
I've got a View.xaml with the following set in Resources-section: <DataTemplate DataType={x:Type ViewModels:MyFirstViewModel}> <Views:MyFirstView
I have the following XAML: <TreeView> <TreeViewItem ItemsSource={Binding} Header=TopMost IsExpanded=True> <TreeViewItem.ItemTemplate> <DataTemplate> <TreeViewItem> <TreeViewItem.Header>
I have following ContextMenu in my xaml: <ContextMenu ItemsSource={Binding RSPContextMenuCommands}> <ContextMenu.ItemContainerStyle> <Style TargetType={x:Type MenuItem}>
I have the following .xaml: <TreeView ItemsSource={Binding EntityInstanceGroupings}> <TreeView.ItemTemplate> <DataTemplate> <TreeViewItem ItemsSource={Binding EntityInstances}> <TreeViewItem.HeaderTemplate>
I have the following code in my XAML: <ItemsControl ItemsSource={Binding Dimensions}> <ItemsControl.ItemTemplate> <DataTemplate> <Grid>
I have the following xaml: <ItemsControl> <ItemsControl.ItemTemplate> <DataTemplate> <Button Content={Binding Name}></Button> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl>

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.