2012-03-11 11 views
0

ファイルがあり、最初の行が電話で、2番目が日付です。 ファイルを読み込んでリストボックスに内容を追加し、すべてが別の行にあります。 2つのテキストボックスを含むようにリストボックスを変更しました。ファイルからデータをバインドする方法テキストファイルを読み込んでリストボックスWP7に追加

<ListBox Name="listBox1" ItemsSource="{Binding}"> 
    <DataTemplate> 
     <StackPanel> 
       <TextBlock Text="{Binding Phone}" FontSize="32"/> 
       <TextBlock Text="{Binding MyDate}" FontSize="16"/> 
     </StackPanel> 
    </DataTemplate> 

? ありがとうございました

答えて

1

thatn行いますが、あなたのデータを表すクラスを作成します。

class PhoneDate 
{ 
public string Phone{get;set;} 
public DateTime MyDate{get;set;} 
} 

を次にリスト

List<PhoneDate> data = //load 

にデータをロードします最後にリストをリストボックスにバインドします。

listBox1.ItemsSource = data; 

これでバインディングが機能します。

+0

これは私が使用してファイル を読み取る方法れる(StreamReaderをリーダ=新しいStreamReaderを(ファイルストリーム)) {行う {mPhone = reader.ReadLine()。 MyDate = reader.ReadLine(); this.listBox1.Items.Add(mPhone); this.listBox1.Items.Add(MyDate); } while(!reader.EndOfStream); –

+0

リストを使用する方法データ= //ロード私はそれを行うために管理 –

+0

が、リストは 'コード' を使用して(StreamReaderをリーダー=新しいStreamReaderを(FILESTREAM))空である { 行う { mPhone = reader.ReadLine (); MyDate = reader.ReadLine(); list.Add(new PhoneDate(mPhone、MyDate)); } while(!reader.EndOfStream); listBox1.ItemsSource = list; } –

0

水平にレイアウトする場合は、StackPanelでOrientation = "Horizo​​ntal"が必要です。

あなたは、ヘッダーと列の位置合わせをしたい場合は、リストビューGridViewのは

関連する問題