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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:29:12+00:00 2026-05-27T02:29:12+00:00

I’m a C# newbie who’s having problems understanding why his first attempt at understanding

  • 0

I’m a C# newbie who’s having problems understanding why his first attempt at understanding XAML bindings isn’t working. I’m following Microsoft’s Data Binding Overview.

I have a single TextBox which will eventually serve as a status window. For now I just want to be able to write arbitrary text strings into it. I also have an instance of the command pattern that I’m testing. My command involves adding a random number to an accumulator and printing out the result to the status view.

Here’s my XAML for the main application window:

<Window x:Class="Experiment.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:c="clr-namespace:Experiment"
        Title="Test" Height="500" Width="700" Name="Test" Closing="Test_Closing" DataContext="{Binding ElementName=statusText}" xmlns:my="clr-namespace:Experiment">
    <Window.Resources>
        <c:StatusViewText x:Key="statusViewText" />
    </Window.Resources>
    <DockPanel HorizontalAlignment="Stretch" Margin="0,0,0,0" Width="Auto">
        <!-- Elements deleted for brevity. -->
        <TextBox Margin="5,5,5,5" Name="statusText" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" AcceptsReturn="True" AcceptsTab="True" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" FontFamily="Courier New" FontSize="12"
                 Text="{Binding Source={StaticResource statusViewText}, Path=statusTextString, Mode=OneWay}"/>
    </DockPanel>
</Window>

And the class representing my data:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Experiment {
    public class StatusViewText {
        public StringBuilder statusText { get; set; }
        public String statusTextString { get; set; }

        public StatusViewText() {
            statusText = new StringBuilder();
        }

        public void Append(string s) {
            if (s != null) {
                statusText.Append(s);
            }

            statusTextString = statusText.ToString();
        }

        public void AppendLine(string s) {
            if (s != null) {
                statusText.AppendLine(s);
            }

            statusTextString = statusText.ToString();
        }
    }
}

Eventually I’ll use a proper converter here from StringBuilder, but I wanted to get the principle down before exploring that complexity.

If my understanding were correct (and obviously it isn’t), this all SHOULD work. The binding target is the TextBox, target property is the Text property. The binding source is the StatusViewText class’s statusTextString property. Yet when I run the command (and debug and see StatusViewText.statusTextString being updated), the TextBox doesn’t update.

I thought that I may need to explicitly add the binding myself, so I tried adding this after InitializeComponent() in the main window constructor:

        statusViewText = new StatusViewText();
        Binding statusViewTextBinding = new Binding("statusTextString");
        statusViewTextBinding.Source = statusViewText;
        statusText.SetBinding(TextBlock.TextProperty, statusViewTextBinding);

but that didn’t work either.

Do I need to fire PropertyChanged events? I thought the entire point of the binding framework is that events are fired and consumed behind the scenes, automagically; but maybe I’m wrong there too.

No obvious errors are coming up in the Output window which leads me to believe that my binding syntax is correct; I’m just missing something else.

Halp!

EDIT 13:14 EDT Thanks mben:

Ok, I did that. Added the following:

public class StatusViewText : INotifyPropertyChanged {
    public void Append(string s) {
        if (s != null) {
            statusText.Append(s);
        }

        statusTextString = statusText.ToString();
        NotifyPropertyChanged("statusTextString");
    }

    public void AppendLine(string s) {
        if (s != null) {
            statusText.AppendLine(s);
        }

        statusTextString = statusText.ToString();
        NotifyPropertyChanged("statusTextString");
    }

    public event PropertyChangedEventHandler PropertyChanged;

    private void NotifyPropertyChanged(String info) {
        if (PropertyChanged != null) {
            PropertyChanged(this, new PropertyChangedEventArgs(info));
        }
    }
}

I debugged to verify that it was going through this code path, and it is. But still no luck. Any other thoughts?

  • 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-27T02:29:13+00:00Added an answer on May 27, 2026 at 2:29 am

    You still need to implement the INotifyPropertyChanged on your StatusViewText.
    The binding system is not going to check the values continuously, you need to notify it when things change.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm making a simple page using Google Maps API 3. My first. One marker
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.