Windows phone 7 wp7中的列表框没有';我不工作
我试图在wp7中呈现一个列表视图,但由于某些原因,它似乎不起作用 我的xamlWindows phone 7 wp7中的列表框没有';我不工作,windows-phone-7,listbox,Windows Phone 7,Listbox,我试图在wp7中呈现一个列表视图,但由于某些原因,它似乎不起作用 我的xaml <!--ContentPanel - place additional content here--> <StackPanel x:Name="ContentPanel2" Grid.Row="1" Margin="12,0,12,0"> <ListBox x:Name="list">
<!--ContentPanel - place additional content here-->
<StackPanel x:Name="ContentPanel2" Grid.Row="1" Margin="12,0,12,0">
<ListBox x:Name="list">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="5">
<Image Source="{Binding ImageUri}" Stretch="None"/>
<TextBlock Text="{Binding Text}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</Grid>
及
private void phoneapplication页面\u已加载(对象发送方、路由目标方)
{
列表数据源=新列表();
添加(新列表(){title=“Shacharit”,imageSource=“Images/Shacharit.png”});
添加(新列表(){title=“Mincha”,imageSource=“Images/Mincha.png”});
添加(新列表(){title=“Arvit”,imageSource=“Images/Arvit.png”});
添加(新列表(){title=“Birkat HaMazon”,imageSource=“Images/shacharit.png”});
list.ItemsSource=数据源;
}
提前感谢尝试以下操作,更改图像和文本块的绑定以绑定到您目前声明的字符串。您正在尝试绑定到ImageURI和文本,但它们在任何代码中都不存在
<!--ContentPanel - place additional content here-->
<StackPanel x:Name="ContentPanel2" Grid.Row="1" Margin="12,0,12,0">
<ListBox x:Name="list" Da>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="5">
<Image Source="{Binding imageSource }" Stretch="None"/>
<TextBlock Text="{Binding title}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</Grid>
为了澄清Jon D的答案,您正在创建代码中具有“imagePath”和“title”属性的数据对象
new list() { title = "Shacharit", imageSource = "Images/shacharit.png" };
但尝试bing到名为“ImageUri”和“Text”的属性
在VS的输出窗口中,您应该可以看到这些绑定错误
下面两行(您在XAML中进行绑定的地方)应该为您解决问题
<Image Source="{Binding imageSource }" Stretch="None"/>
<TextBlock Text="{Binding title}"/>
它似乎不起作用意味着发生了什么?太好了,很乐意帮忙。你能接受我和僵尸羊的回答吗。干杯
new list() { title = "Shacharit", imageSource = "Images/shacharit.png" };
<Image Source="{Binding imageSource }" Stretch="None"/>
<TextBlock Text="{Binding title}"/>