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>

  • 相关阅读:
    Java深度历险(四)——Java垃圾回收机制与引用类型
    Java深度历险(三)——Java线程​:基本概念、可见性与同步
    Java深度历险(一)——Java字节代码的操纵(转)
    SVN问题:Cleanup failed to process the following paths: xxxxxx
    解决 ORA-12154: TNS:could not resolve service name
    Linq 实现普通sql中 where in 的功能
    C# 操作电脑 关机 重启 注销 休止 休眠
    使用C#代码追加和提交文件到SVN服务器
    access 2007 vba (亖)
    access 2007 vba 开发中学到的知识(三)
  • 原文地址:https://www.cnblogs.com/xingchen/p/1978430.html
Copyright © 2011-2022 走看看