日期:2014-05-17  浏览次数:20883 次

WPF,这个绑定源怎么是集合呢?

<Grid HorizontalAlignment="Left" Height="368" VerticalAlignment="Top" Width="596">
    <TextBlock HorizontalAlignment="Left" Margin="84,34,0,0" TextWrapping="Wrap" Text="姓名:" VerticalAlignment="Top"/>
    <TextBox HorizontalAlignment="Left" Height="23" Margin="123,30,0,0" TextWrapping="Wrap" Text="{Binding Path=Name}" VerticalAlignment="Top" Width="120"/>
    <TextBlock HorizontalAlignment="Left" Margin="84,72,0,0" TextWrapping="Wrap" Text="年龄:" VerticalAlignment="Top"/>
    <TextBox HorizontalAlignment="Left" Height="23" Margin="123,68,0,0" TextWrapping="Wrap" Text="{Binding Path=Age}" VerticalAlignment="Top" Width="120"/>
    <TextBlock HorizontalAlignment="Left" Margin="84,111,0,0" TextWrapping="Wrap" Text="地址:" VerticalAlignment="Top"/>
<TextBox HorizontalAlignment="Left" Height="23" Margin="123,107,0,0" TextWrapping="Wrap" Text="{Binding Path=Adress}" VerticalAlignment="Top" 
Width="120"/>
    <Button Name="cmdprev" Content="&lt;" HorizontalAlignment="Left" Margin="154,167,0,0" HorizontalContentAlignment="Center" VerticalAlignment="Top" Height="26" Click="cmdprev_Click"/>
    <Button Name="cmdnext" Content="&gt;" HorizontalAlignment="Left" Margin="197,167,0,0" HorizontalContentAlignment="Center" VerticalAlignment="Top" Height="26" Click="cmdnext_Click"/>
    <TextBlock Name="textblock1" HorizontalAlignment="Left" Margin="173,172,0,0" TextWrapping="Wrap" Text="10" VerticalAlignment="Top"/>
</Grid>


public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        List<Person> list = new List<Person>() 
        {
            new Person(){Name="熊俊",Adress="北京",Age=43},
            new Person(){Name="张三",Adress="美国",Age=52},
            new Person(){Name="李四",Adress="英国",Age=45},
        };
        this.DataContext = list;