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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:52:24+00:00 2026-05-13T16:52:24+00:00

Total beginner in WPF so bear with me. I building a proof of concept

  • 0

Total beginner in WPF so bear with me.

I building a proof of concept application before I go ahead with it. I have decided to try building it using WPF first.

This is the scenario:

I have:

  • a View=CustomerView (userControl with a button "Buy Products")
  • a txtbox (append all the actions that occurs)
  • ViewModel=CustomerViewModel (talks to the service etc.. and gets results
  • Model =Customer (simple class with properties with InotifyPropertyChanged implemented

Given that I have a collection of products and for each product that I buy I need to APPEND TEXT TO the txtBox in the userControl printing all the actions that occurs, the textBox should look like

Start buying .....
Product 1 Sold
Product 2 Sold
Fineshed....

My problem is that despite I notify successfully after each item is sold I cannot seem to see how I can bind or make "Product 1 Sold,Product 2 appear in the textbox.

In windows forms I would have a userControl with a property called ProductStatus and whenever notified I would appendText to the textBox.
"I put beginInvoke as I was getting threadCross operation" when coming from a service. That is another problem that I will have to investigate

private ProductStatus _productStatus;
public ProductStatus Status
{
  get { return _productStatus; }
  set
  {
    _printStatus = value;                 
    BeginInvoke((MethodInvoker)(() => txtProductResult.AppendText(string.Format("Product Sold {0}", Environment.NewLine))));  
  }
}

How do I append text to myTextBox for each item I sell?

=================Added current code===============================

    void LogChanged(object sender, NotifyCollectionChangedEventArgs e) 
        { 
            foreach(object item in e.NewItems) 
            { 
                txtProduct.AppendText(item.ToString()); 
            } 
        } 
        
         <TextBox Margin="12,41,12,59" Name="txtPrintResult" />
       <TextBox Text="{Binding TicketPrintLog, Mode=OneWay}" Margin="12,41,12,12" />
       
       
            ProductModel
            =============
             public string ProductLog{ get; set; }
              
              
            ProductViewModel
            ==================
            public string ProductLog
            {
                get { return _ProductModel.ProductLog; }
            }   
            internal void AppendToProductLogText(string text)
            {
                _ProductModel.ProductLog += text + Environment.NewLine;
                OnPropertyChanged("ProductLog");
            } 
            
            void ProductSoldNotificationReceived(object sender, notificationEventArgs e)
            {
                //THIS FIRES WHENEVER I PRODUCT IS SOLD.
                AppendToProductLogText(e.Message);
             }
            
            ProductView (userControl) XAML
            ================================
            <TextBox Margin="12,41,12,59" Name="txtResult" Text="{Binding ProductLog, Mode=OneWay}" />  
            
            IN CODE BEHIND I DO
              
              public void Action1()
              {
                txtResult.AppendText(_productViewModel.ProductLog);
              }
               public void SellProductAction()
              {
                txtResult.AppendText(_productViewModel.ProductLog);
              }

The problem i have is that i still have todo this

        txtResult.AppendText(_productViewModel.ProductLog); 

which defeats the point on databinding also when executing SellproductAction I only get notified about the last item, it doesn’t append Product1 sold, Product 2 sold etc…

Any ideas?

  • 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-13T16:52:25+00:00Added an answer on May 13, 2026 at 4:52 pm

    First off, you can still do this the Windows Forms way, by appending the new text to the existing text:

    txtProductResult = txtProductResult + Environment.NewLine + "Product sold";
    

    (If you do this from a background thread you will need to use txtProductResult.Dispatcher.BeginInvoke instead of txtProductResult.BeginInvoke.)

    However, the idiomatic way to do this in WPF is with data binding. So you would create a ProductSalesLog property on your view model, and bind the TextBox to that property. Then, whenever you update the ProductSalesLog property in the view model, the TextBox will update automatically. Note that your view model must implement INotifyPropertyChanged and must raise the PropertyChanged event for the ProductSalesLog property. Thus:

    public class CustomerViewModel : INotifyPropertyChanged
    {
      private string _productSalesLog = String.Empty;
      public string ProductSalesLog
      {
        get { return _productSalesLog; }
      }
    
      internal void AppendSalesLogText(string text)
      {
        _productSalesLog += text + Environment.NewLine;
        OnPropertyChanged("ProductSalesLog");
      }
    }
    

    And in your view:

    <TextBox Text="{Binding ProductSalesLog, Mode=OneWay}" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok I am a total beginner with the Solaris Operating system and I need
So, I am a total beginner in any kind of Windows related programming. I
Total newbie question but this is driving me mad! I'm trying this: myInt =
I get the Total length of columns in constraint is too long. erro from
I am a total Groovy newbie. I saw the following code here . def
I'm a total newbie, but I was writing a little program that worked on
I'm a total amateur writing a small App to track to changes in folders.
What percentage of your total development effort do you spend on implementing and maintaining
I'm a total newbie to SVN and haven't been able to find an answer
I own a total of one iPhones. I want to test my app on

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.