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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:39:41+00:00 2026-06-13T20:39:41+00:00

I’ve been playing about with data binding and using the INotifiedProperty interface (including the

  • 0

I’ve been playing about with data binding and using the INotifiedProperty interface (including the new .Net 4.5 CallerMemberName attribute).

All is working well but I can’t understand why updating an object’s property refreshes the label it’s bound to but refreshing the object itself doesn’t re-fresh the label.

For example, if I have the following Window:

<Grid Name="TestGrid">
    <!-- Grid definitions here -->

    <Label Grid.Column="0" Grid.Row="0">The value is :</Label>
    <Label Grid.Column="1" Grid.Row="0" Content="{Binding TestVal1}"/>

    <Button Grid.Column="0" Grid.Row="1" Click="Button_Click_1">Refresh</Button>
    <Button Grid.Column="1" Grid.Row="1" Click="Button_Click_2">New class instance</Button>
</Grid>

With the following code behind it:

public MainWindow()
    {
        InitializeComponent();

        TestGrid.DataContext = TestClass1;
    }

    public TestClass TestClass1 = new TestClass();

    private void Button_Click_1(object sender, RoutedEventArgs e)
    {
        TestClass1.ChangeTestVal1();
    }

    private void Button_Click_2(object sender, RoutedEventArgs e)
    {
        TestClass1 = new TestClass();
    }

Which is bound the following class:

public class TestClass : INotifyPropertyChanged
{
    public TestClass()
    {
        ChangeTestVal1();
    }


    public event PropertyChangedEventHandler PropertyChanged;

    internal void OnPropertyChanged([CallerMemberName] String caller = null)
    {
        var handler = PropertyChanged;
        if (handler != null)
        {
            handler(this, new PropertyChangedEventArgs(caller));
        }
    }

    private string _TestVal1;
    public string TestVal1
    {
        get { return _TestVal1; }
        set
        {
            if (value != _TestVal1)
            {
                _TestVal1 = value;
                OnPropertyChanged();
            }
        }
    }

    public void ChangeTestVal1()
    {
        TestVal1 = "TestVal1 = " + DateTime.Now.ToString("dd-MMM-yyyy HH:mm:ss");
    }

The result of is that clicking the “Refresh” button works and clicking the “New class instance” doesn’t.

My question is, I know I can add “TestGrid.DataContext = TestClass1” to the code for the second button to get it to work but surely it should detect the instance of the TestClass changing when it’s refreshed? Am I setting the binding up incorrectly?

  • 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-13T20:39:42+00:00Added an answer on June 13, 2026 at 8:39 pm

    You’re assigning TestGrid.DataContext = TestClass1; Changing the object reference of the variable to a different object does not change the object reference in the DataContext property of the TestGrid. Take a look at the basics of OOP for more details

    Edit: I mean, doing TestClass1 = new TestClass(); does not change the fact that the Datacontext of your grid is still the same object instance it was before.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

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.