I have a file in which the first line is a phone and the second is a date. I read the file and add the content to a listbox fine and everything is in a different row. Now i changed the listbox to contain 2 textboxes.
<ListBox Name="listBox1" ItemsSource="{Binding}">
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Phone}" FontSize="32"/>
<TextBlock Text="{Binding MyDate}" FontSize="16"/>
</StackPanel>
</DataTemplate>
How to bind the data from the file? Thank you
Create a class to represent your data:
class PhoneDate
{
public string Phone{get;set;}
public DateTime MyDate{get;set;}
}
Then load your data into a list
List<PhoneDate> data = //load
Finally bind the list to the listbox:
listBox1.ItemsSource = data;
Now your bindings will work.
If you want them to lay out horizontally then you need Orientation="Horizontal" on the StackPanel.
If you want header and column alignment then ListView Gridview will do thatn
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.