Click here to Skip to main content
15,867,704 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How do I bind data in Textblock?
when I write data in textbox then press add button and it will be bind data in textblock using listview WPF MVVM ?

refer this link
C#
Visit Question Its URL is http://www.c-sharpcorner.com/forums/bind-data-in-wpf-mvvm2
Posted
Updated 30-Dec-15 19:57pm
v3

1 solution

Hi, this is simple, just create a List of string (List<string>). Bind the craeted List to ListBox's ItemsSource. And just add your textbox's input string to this List whenever you press the button, it will reflects in the listbox.
 
Share this answer
 
Comments
Dhawal Sojitra 31-Dec-15 1:32am    
can you go with step by step?
VR Karthikeyan 31-Dec-15 2:10am    
Sorry, I was wrong. Use Observable Collection of string (ObservableCollection<string>) instead List<string>, it works.
VR Karthikeyan 31-Dec-15 2:11am    
create property like,

private ObservableCollection<string> _StringList = new ObservableCollection<string>();

public ObservableCollection<string> StringList
{
get {return _StringList;}
set {_StringList=value; }
}

set ListBox's ItemsSource like,

StringListBox.ItemsSource=StringList;

Add TextBox's input string to the Observable Collection like (in button click event),

StringList.Add(txtString.Text);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900