不知道为什么,前台ListView里不能够显示出来绑定的对象
我在学习Windows 10 通用应用开发时遇到了这个问题,自己解决不了,求论坛里各位大神的帮帮忙吧,我还是入门阶段。不胜感激啊。代码在这里
前台XAML
x:Class="JustaTry.Controls.CountryNumberList"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:JustaTry.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="1920"
d:DesignWidth="1080">
<Popup Visibility="Visible">
<ListView Name="CountryNumberListView" ScrollViewer.HorizontalScrollMode="Disabled" ScrollViewer.VerticalScrollMode="Auto"
Width="1080" Height="1920"
Tapped="CountryNumberListView_Tapped"
Visibility="Visible"
ItemsSource="{x:Bind CountryNumberSet}">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Visibility="Visible">
<TextBlock Width="640" Height="160" Text="{Binding CountryNumber.Country}" FontSize="160"></TextBlock>
<TextBlock Width="440" Height="160" Text="{Binding CountryNumber.Number}" FontSize="160"></TextBlock>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Popup>
后台
namespace JustaTry.Controls
{
public sealed partial class CountryNumberList : UserControl
{
public CountryNumberList()
{
this.InitializeComponent();
ObservableCollection<CountryNumber> CountryNumberSet = new ObservableCollection<CountryNumber>()
{
new CountryNumber() { Country = "中国", Number = "+86" },
new CountryNumber() { Country = "美国", Number = "+86" },
new CountryNumber() { Country = "英国", Number = "+86" },
new CountryNumber() { Country = "法国", Number = "+86" },
new CountryNumber() { Country = "荷兰", Number = "+86" }
};
}
public void CountryNumberListView_Tapped(object sender, RoutedEventArgs e)
{
}
public class CountryNumber
{
public String Country { get; set; }//默认为私有类,需要注意声明public
public String Number { get; set; }
}
public ObservableCollection<CountryNumber> CountryNumberSet = new ObservableCollection<CountryNumber>();
}
}