ListBox数据绑定的问题
前端:
<ListBox HorizontalAlignment="Left" Height="100" Margin="32,47,0,0" VerticalAlignment="Top" x:Name="list" Width="190">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Width="20" Height="20" Text="{Binding Name}"></TextBlock>
<TextBlock Width="40" Height="40" Text="{Binding Age}" Grid.Column="1"></TextBlock>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
后端:
class User
{
public string Name
{
get;
set;
}
public int Age
{
get;
set;
}
}
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
List<User> ob = new List<User>();
ob.Add(new User() { Name = "wang", Age = 1 });
ob.Add(new User() { Name = "Li", Age = 11 });
list.ItemsSource = ob;
}
}
ListBox 为什么不出数据啊?