Possible Duplicate:
WPF ListBox - Display properties of the ItemSource
I m 试图通过一个文本箱和Addutton...在清单Box中展示物品的解决办法 我是妇联的新鲜事,我几乎不谈这个数字(在一周禁止我头对我的桌子......鲁尔之后)
问题在于,名单箱正在配备“WinBudget”。 账户”而不是列入清单箱的实际项目。
请提供帮助。
// the model is the basic design of an object containing properties
// and methods of that object. This is an account object.
public class Account : INotifyPropertyChanged
{
private string m_AccountName;
public event PropertyChangedEventHandler PropertyChanged;
public string AccountName
{
get { return m_AccountName;}
set
{
m_AccountName = value;
OnPropertyChanged("AccountName");
}
}
protected void OnPropertyChanged(string name)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(name));
}
}
}
<ListBox Name="MyAccounts" />
http://www.ohchr.org。
// create a collection of accounts, then whenever the button is clicked,
//create a new account object and add to the collection.
public partial class Window1 : Window
{
private ObservableCollection<Account> AccountList = new ObservableCollection<Account>();
public Window1()
{
InitializeComponent();
AccountList.Add(new Account{ AccountName = "My Account" });
this.MyAccounts.ItemsSource = AccountList;
}
private void okBtn_Click(object sender, RoutedEventArgs e)
{
AccountList.Add(new Account{ AccountName = accountaddTextBox.Text});
}
}