zoukankan      html  css  js  c++  java
  • 在 ListBox 中显示数据

    使用 XAML 元素填充 ListBox

    <ListBox Width="150" Margin="0,5,0,10">
    <TextBlock Text="TextBlock" />
    <TextBox Text="TextBox" />
    <Button Content="Button" />
    <Rectangle Fill="LightBlue" Height="20" Width="100" Margin="2,2,2,2"/>
    <Ellipse Fill="Coral" Height="20" Width="150" Margin="2,2,2,2"/>
    </ListBox>

    使用 ItemsSource 属性填充 ListBox

    <Grid>
    <Grid.Resources>
    <src:Customers x:Key="customers"/>
    </Grid.Resources>
    <ListBox ItemsSource="{StaticResource customers}" Width="250" Margin="0,5,0,10"
    DisplayMemberPath
    ="LastName"/>
    </Grid>
    public class Customer
    {
    public String FirstName { get; set; }
    public String LastName { get; set; }
    public String Address { get; set; }

    public Customer(String firstName, String lastName, String address)
    {
    this.FirstName = firstName;
    this.LastName = lastName;
    this.Address = address;
    }
    }

    public class Customers : ObservableCollection<Customer>
    {
    public Customers()
    {
    Add(
    new Customer("Michael", "Anderberg",
    "12 North Third Street, Apartment 45"));
    Add(
    new Customer("Chris", "Ashton",
    "34 West Fifth Street, Apartment 67"));
    Add(
    new Customer("Cassie", "Hicks",
    "56 East Seventh Street, Apartment 89"));
    Add(
    new Customer("Guido", "Pica",
    "78 South Ninth Street, Apartment 10"));
    }
    }
  • 相关阅读:
    轮播无缝
    项目开发的注意
    再聊移动端页面的适配
    如何在Vue项目中使用vw实现移动端适配
    移动端适配文章
    vue-cli 配置flexible px2rem-loader安装配置
    vuex复习笔记
    vue-router复习笔记
    vue-cli 笔记
    内置组件 -slot讲解
  • 原文地址:https://www.cnblogs.com/landexia/p/1984319.html
Copyright © 2011-2022 走看看