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>

  • 相关阅读:
    解决firefox的button按钮文字不能垂直居中
    郁闷呢
    我的生活走入正轨
    空闲的日子写写日记
    今天可以写心事
    终于可以写字了
    有地方可以发表自己的心事了。
    Shopify:产品详情页购买按钮下方支持的支付方式图标如何修改?
    Wordpress报错:Allowed memory size of 134217728 bytes exhausted
    安装Xshell报错:由于找不到MSVCR110.dll,无法继续执行代码。重新安装程序可能会解决此问题
  • 原文地址:https://www.cnblogs.com/xingchen/p/1978430.html
Copyright © 2011-2022 走看看