【发布时间】:2015-02-21 12:57:10
【问题描述】:
我正在尝试创建项目的 ListView 并能够删除它们。这是我的代码。我无法获取要显示的项目列表。我没有找到绑定 ListViews 的简单示例,因此我可以理解确切的概念。你能告诉我我做错了什么吗?
PS。 myListOfItems 是一个带有字符串的列表。该项目是 WP 8.1 WinRT。
public class MedClass
{
public string medName { get; set; }
}
public class MedClassRoot
{
public List<MedClass> medNames { get; set; }
}
public sealed partial class MedSavedPage : Page
{
protected override void OnNavigatedTo(NavigationEventArgs e)
{
MedClassRoot root = new MedClassRoot();
root.medNames = new List<MedClass>();
foreach (var element in myListOfItems)
{
root.medNames.Add(new MedClass {medName = element});
}
MedSaved_ListView.DataContext = root;
//MedSaved_ListView.ItemsSource = root;
}
<ListView DataContext="{Binding root}"
x:Name="MedSaved_ListView"
HorizontalAlignment="Left"
Height="507"
Margin="10,73,0,0"
VerticalAlignment="Top"
Width="380" Tapped="MedSaved_ListView_Tapped">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Height="30">
<TextBlock Text="{Binding medName}" FontSize="16"/>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
【问题讨论】:
标签: c# xaml windows-runtime windows-phone-8.1 winrt-xaml