• 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;选择器, 否则绑定后内容不显示。

  • 相关阅读:
    WIN10平台下基于Anaconda环境的pyOpt安装
    「Java分享客栈」随时用随时翻:微服务链路追踪之zipkin搭建
    【Java分享客栈】未来迈向高级工程师绕不过的技能:JMeter压测
    全网唯一 | 互联网公司微信支付宝服务商入驻流程图文指南
    shellcode编写
    C语言函数调用栈
    栈溢出基础
    Git学习笔记
    mixer类型 DAPM kcontrol 写流程
    BE dailink fixup callback函数
  • 原文地址:https://www.cnblogs.com/qixue/p/3223386.html
Copyright © 2020-2023  润新知