Total beginner in WPF so bear with me.
I building a proof of concept application before with go ahead with it.I have decided to give it a go a WPF.
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 defeates the point on databinding also when executing SellproductAction I only get notified about the last item ,It doesnt append Product1 sold ,Product 2 sold etc....
Any ideas