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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T06:30:39+00:00 2026-05-19T06:30:39+00:00

I am a reasonably experienced programmer but new to WPF. I have bound a

  • 0

I am a reasonably experienced programmer but new to WPF. I have bound a textblock on a form to an object property, but it is not updating the form as I would expect when I set the property. The binding appears to be done correctly–if I troubleshoot with a button that updates the property the form changes, but when I initially set the property in the form’s constructor by parsing a local XML file it doesn’t update.

I am using C# and VS2010. Could someone guide me for a few steps or refer me to a book or coding tool that gets me over this hump. Also, please note that I chose to structure things way by imitating the paradigm used in the “How Do I: Build My First WPF Application” at windowsclient.net. If you think I’m going about it the wrong way, I would appreciate a pointer to a better tutorial.

Form XAML:

<Window ...
  xmlns:vm="clr-namespace:MyProjectWPF.ViewModels">
  <Grid>
    <Grid.DataContext>
      <vm:MyConfigurationViewModel />
    </Grid.DataContext>

    <TextBlock Name="textBlock4" Text="{Binding Path=Database}" />
  </Grid>

MyConfigurationViewModel class definition:

class MyConfigurationViewModel : INotifyPropertyChanged
{
  private string _Database;

  public string Database
  {
    get { return _Database; }
    set { _Database = value; OnPropertyChanged("Database"); }
  }

  public void LoadConfiguration()
  {
    XmlDocument myConfiguration = new XmlDocument();
    myConfiguration.Load("myfile.xml");
    XmlNode root = myConfiguration.DocumentElement;

    Database = root["Database"].InnerText;
  }

  public event PropertyChangedEventHandler PropertyChanged;

  private void OnPropertyChanged(string Property)
  {
    if (PropertyChanged != null)
      PropertyChanged(this, new PropertyChangedEventArgs(Property));
  }

And the codebehind my XAML form:

public partial class MyForm : Window
{
  private ViewModels.myConfigurationViewModel mcvm
    = new ViewModels.myConfigurationViewModel();

  public MyForm()
  {
    mcvm.LoadConfiguration();
  }
  • 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-19T06:30:41+00:00Added an answer on May 19, 2026 at 6:30 am

    You have two instances of myConfigurationViewModel. One is created inside the XAML and the second one is created inside the form’s codebehind. You are calling LoadConfiguration on the one in the code behind, which is never set as the form’s DataContext.

    Remove this from the XAML:

    <Grid.DataContext>       
        <vm:MyConfigurationViewModel />
    </Grid.DataContext> 
    

    and change the constructor to this:

    public MyForm()
    {
        mcvm.LoadConfiguration();    
        DataContext = mcvm;
    }   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a reasonably experienced Java programmer but relatively new to Java2D. I'm trying to
I am reasonably new to C++ and have limited experience of templates. At the
I'm currently working on a reasonably complicated data input form, based around ASP.NET Web
I am looking for examples of reasonably short, but reasonably complicated segments of code
First of all, a disclaimer: I have experience in other languages, but am still
I am a reasonably competent programmer, with about 11 years experience. I particularly like
I am a reasonably experienced C# developer (about 5 year experience) that has recently
I have a reasonably large (thousands of files) project which is divided between client
I have reasonable experience to manage my own server, so gogrid style management is
Is there some reasonably cross platform way to create a thumbnail image given a

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.