Binding and appendText result in a text field. Complete newbie to WPF.Need help

General newbie to WPF, so bear with me.

I built the proof of the conceptual application before continuing with it. I decided to give it go WPF.

This is the scenario:

I have:

  • a View = CustomerView (userControl with Buy item button)
  • txtbox (add all actions that occur)
  • ViewModel = CustomerViewModel (negotiates with the service, etc. and gets the results
  • Model = Customer (simple class with properties with InotifyPropertyChanged embedded

Given that I have a set of products, and for each product I buy, I need to APPLY TEXT. In txtBox in userControl output all the actions that occur, the text field should look like

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

, , , , , " 1 , 2 .

Windows userControl ProductStatus, , , .   " beginInvoke, threadCross" . ,

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

myTextBox ?

================= =========================== ====

    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);
              }

,

        txtResult.AppendText(_productViewModel.ProductLog); 

SellproductAction, , Product1, 2 ..

+3
2

-, Windows Forms, :

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

( , txtProductResult.Dispatcher.BeginInvoke txtProductResult.BeginInvoke.)

, WPF . , ProductSalesLog TextBox . , , ProductSalesLog , TextBox . , INotifyPropertyChanged PropertyChanged ProductSalesLog. :

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");
  }
}

:

<TextBox Text="{Binding ProductSalesLog, Mode=OneWay}" />
+4

WPF - , , . viewmodel model INotifyPropertyChanged ( propertyChanged).

, . , . , , , , , PropertyChanged ,

0

Source: https://habr.com/ru/post/1732725/


All Articles