zoukankan      html  css  js  c++  java
  • Listbox Binding ItemsSource

    把List<CourseItem>绑定到ListBox.

    前台绑定:

                    <ListBox x:Name="ItemBox" Grid.Row="1">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <Grid Width="400" Height="150" Margin="12,0,0,20">
                                    <Border Background="#01BCF3">
                                        <Image Source="" Stretch="UniformToFill" AutomationProperties.Name="{Binding Title}" />
                                    </Border>
                                    <StackPanel VerticalAlignment="Bottom" Margin="10,0" >
                                        <TextBlock Text="{Binding Title}" TextWrapping="Wrap" Margin="10,0" FontSize="24" Tap="TextBlock_Tap_1" Style="{StaticResource PhoneTextTitle3Style}" />
                                        <TextBlock Text="{Binding PublishDate}" Margin="10,0" FontSize="18" Foreground="#FF8F8F8F"/>
                                    </StackPanel>
                                </Grid>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>


    后台绑定:

    ItemBox.ItemsSource = CommonConfig.PopularCourses;

    其中, PopularCourses 的类型是List<CourseItem>, CourseItem 的定义如下:

            public static List<CourseItem> PopularCourses
            {
                get;
                set;
            }
    
        class CourseItem
        {
            private string _title;
            public string Title { get { return _title; } set { _title = value; } }
    
            private string _id;
            public string ID { get { return _id; } set { _id = value; } }
    
            private string _description;
            public string Description { get { return _description; } set { _description = value; } }
    
            private string _totalPoints;
            public string TotalPoints { get { return _totalPoints; } set { _totalPoints = value; } }
    
            private string _level;
            public string Level { get { return _level; } set { _level = value; } }
    
            private string _owner;
            public string Owner { get { return _owner; } set { _owner = value; } }
    
            private string _rating;
            public string Rating { get { return _rating; } set { _rating = value; } }
    
            private Category _category;
            public Category Category { get { return _category; } set { _category = value; } }
    
            private DateTime _pubDate;
            public DateTime PublishDate { get { return _pubDate; } set { _pubDate = value; } }
    
            public List<Module> Modules { get; set; }
        }

    注意: CourseItem中各属性定义是一定要有get;选择器, 否则绑定后内容不显示。

  • 相关阅读:
    PAT 1035. 插入与归并(25)
    PAT 1034. 有理数四则运算(20)
    PAT 1033. 旧键盘打字(20)
    PAT 1032. 挖掘机技术哪家强(20)
    PAT 1031. 查验身份证(15)
    PAT 1030. 完美数列(25)
    PAT 1029. 旧键盘(20)
    PAT 1028. 人口普查(20)
    PAT 1027. 打印沙漏(20)
    PAT 1026. 程序运行时间(15)
  • 原文地址:https://www.cnblogs.com/qixue/p/3223386.html
Copyright © 2011-2022 走看看