我在我的程序中使用 hubsection 并且<HubSection>
有一个 ListView。但我无法将数据绑定到 ListView。我曾尝试使用{binding}
,但在输出中出现空白,并且在使用x:bind
时出现错误
没有为 DataTemplate 定义 DataType。包含 x:Bind 的模板需要使用 'x:DataType' 指定 DataType
帮我解决这个问题。这是我的代码:
.xaml
<Hub Header="abc" FontWeight="Bold">
<HubSection Header="header1" x:Name="hub1">
<DataTemplate >
<ListView x:Name="list1" ItemsSource="{x:Bind info}">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<Image Source="{X:Bind image}"></Image>
<TextBlock Text="{x:Bind name}"/>
</StackPanel>
<TextBlock Text="{x:Bind bio}"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</DataTemplate>
</HubSection>
<HubSection Header="header 2">
<DataTemplate>
</DataTemplate>
</HubSection>
</Hub>
</Grid>
。CS
namespace app1
{
public class info
{
public String name { get; set; }
public String bio { get; set; }
public String image { get; set; }
}
public sealed partial class abcde : Page
{
ObservableCollection<info> obsinfo = new ObservableCollection<info>();
public abcde()
{
this.InitializeComponent();
filldata();
}
void filldata()
{
obsinfo.Add(new info { name = "data1", image = "images/data1.png", bio = "" });
obsinfo.Add(new info { name = "data2", image = "images/data2.png", bio = "" });
}
}
}