1
如何將文本文件名綁定到使用C#的Windows Metro風格應用程序中的ListBox控件?將文本文件綁定到XAML列表框控件
或者:
如何綁定一個Dictionary()的XAML ListBox控件?
如何將文本文件名綁定到使用C#的Windows Metro風格應用程序中的ListBox控件?將文本文件綁定到XAML列表框控件
或者:
如何綁定一個Dictionary()的XAML ListBox控件?
在閱讀文檔,搜索和提問之後似乎是無盡的時間;我設法弄清楚了自己。
下面是工作只是因爲我需要它在我的處境代碼:
XAML:
<ListBox Name="NotesList">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Filename}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
代碼隱藏:
public class NoteView
{
public string Filename { get; set; }
public string Contents { get; set; }
}
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached. The Parameter
/// property is typically used to configure the page.</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
var noteList = new ObservableCollection<NoteView>();
for (int i = 0; i < 10; i++)
{
noteList.Add(new NoteView { Filename = "Sample note " + i });
}
NotesList.ItemsSource = noteList;
}