Do like this :
Class Person
{
private String name;
public String Name
{
get{return name;}
set{name=value;}
}
private int code;
public int Code
{
get{return code;}
set{code=value;}
}
public Person(String name,int code)
{
Name=name;
Code=code;
}
}
Class PersonCollection:ObservableCollection<person>
{
}
public Window1
{
InitializeComponent();
PersonCollection perColl=new PersonCollection();
listBox.ItemsSource=perColl;
}
perColl.Add(new Person(txtName.Text,int.Parse(txtCode.Text));</person>
Move over to your XAML :
<listbox name="listBox">
<listbox.itemtemplate>
<datatemplate>
<stackpanel orientation="Horizontal">
<textblock text="{Binding" path="Name}/">
<textblock text="{Binding" path="Code}/">
</textblock></textblock></stackpanel></datatemplate>
</listbox.itemtemplate>
</listbox>
The Stackpanel above in your DataTemplate will keep the name and code in a horizontal way.
Hope it helped!