zoukankan      html  css  js  c++  java
  • listbox控件的数据绑定带图片

    关于listbox控件带图片列表形式的绑定

    系统运行的效果

    参考代码如下:

    这里一定要注意的是:数据绑定的格式,

    一定要注意绑定他们的属性,而不是绑定他们的成员变量

    using System;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Ink;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using System.Collections;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;

    namespace WindowsPhoneApplication1.classLibrary
    {
        public class Book
        {
            public string bookName = string.Empty;
            public string bookprice = string.Empty;
            public string bookpic = string.Empty;
            //
            public string bPrice
            {
                set
                {
                    bookprice = value;
                }
                get
                {
                    return bookprice;
                }
            }
            //
            public string bName
            {
                set
                {
                    bookName = value;
                }
                get
                {
                    return bookName;
                }
            }
            //
            public string bPic
            {
                set
                {
                    bookpic = value;
                }
                get
                {
                    return bookpic;
                }
            }
            public Book()
            {

            }
            public Book(string name, string price, string pic)
            {
                this.bookName = name;
                this.bookprice = price;
                this.bookpic = pic;
            }
        }
    }

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using Microsoft.Phone.Controls;
    using WindowsPhoneApplication1.classLibrary;

    namespace WindowsPhoneApplication1.page
    {
        public partial class listboxPage : PhoneApplicationPage
        {
            public listboxPage()
            {
                InitializeComponent();

                List<Book> TT = new List<Book>();
                Book bk = new Book("xingchen", "100", "../Images/1.png");
                TT.Add(bk);
                bk = new Book("xingchen", "100", "../Images/1.png");
                TT.Add(bk);
                lstData.ItemsSource = TT;
            }
        }
    }

    前台代码

    //定义前台数据绑定的格式

           <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
                <ListBox x:Name="lstData">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <Image Margin="8" VerticalAlignment="Top" Source="{Binding  Path=bPic}" Width="100" Height="100" />
                                <StackPanel>
                                    <TextBlock Margin="8" Width="250" FontSize="36"  Foreground="White" TextWrapping="Wrap" VerticalAlignment="Top" HorizontalAlignment="Left" Text="{Binding  Path=bName}" />
                                    <TextBlock Width="100" Margin="8,0,8,8" VerticalAlignment="Top" HorizontalAlignment="Left" Text="{Binding  Path=bPrice,}"/>
                                </StackPanel>
                            </StackPanel>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>

            </Grid>
        </Grid>

  • 相关阅读:
    Design a stack that supports getMin() in O(1) time and O(1) extra space
    Python的sys.argv用法
    数据库系统概论学习4-SQL 语句和关系代数(二)单表查询
    数据库系统概论学习3-SQL 语句和关系代数(一)SQL 入门
    数据库系统概论学习2-《关系数据库与 E/R 模型》
    MySQL实验1: 新建一个名为 library 的数据库,包含 book、reader 两张表,根据自己的理解安排表的内容并插入数据。
    如何在Eclipse环境下安装PyDev并成功运行Python3.6代码
    模型融合之blending和stacking
    Pandas基础用法-数据处理【全】-转
    各种排序算法-用Python实现
  • 原文地址:https://www.cnblogs.com/xingchen/p/1978430.html
Copyright © 2011-2022 走看看