这篇文章主要介绍了C#中WPF ListView绑定数据的示例分析,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。
创新互联是专业的垣曲网站建设公司,垣曲接单;提供网站制作、网站设计,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行垣曲网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!C#中WPF ListView绑定数据的实例详解
WPF中ListView用来显示数据十分方便, 我们可以将它分成几个列,每一个列用来显示一条数据,但是又是在一方之中。

那么怎样实现这样的效果的呢,这就要用绑定了。
我们先来看一看他的xmal代码
上面的代码中每一个GridViewColumn都有一个绑定{Bind Path=作为绑定源的类中的成员属性}
下面来看一下绑定的类
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EmailClient
{
class MailList : INotifyPropertyChanged
{
public string senduser;
public string topic;
public string file;
public string time;
public event PropertyChangedEventHandler PropertyChanged;
public string Senderuser
{
get
{
return senduser;
}
set
{
senduser = value;
if (this.PropertyChanged != null)//激发事件,参数为Age属性
{
this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs("Age"));
}
}
}
public string Topic
{
get
{
return topic;
}
set
{
topic = value;
if (this.PropertyChanged != null)//激发事件,参数为Age属性
{
this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs("Age"));
}
}
}
public string Ffile
{
get
{
return file;
}
set
{
file = value;
if (this.PropertyChanged != null)//激发事件,参数为Age属性
{
this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs("Age"));
}
}
}
public string Time
{
get
{
return time;
}
set
{
time = value;
if (this.PropertyChanged != null)//激发事件,参数为Age属性
{
this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs("Age"));
}
}
}
public MailList() { }
public MailList(string senduser,string topic,string file,string time)
{
this.senduser = senduser;
this.topic = topic;
this.file = file;
this.time = time;
}
}
}现在我们可以看到我们刚才绑定的属性就在这个类中,那么该怎样应用呢
下面来看一下我的应用代码
private Listmaillist;
maillist = new List();
以上的代码是声明一个list来保存我们插入的数据的,由于我的源代码是从服务器中得到的邮件列表。
maillist.Add(new MailList("xxxxxx", "xxxxxxxx", "xxxxxx", "xxxxxx"));receiveList.ItemsSource = maillist;
如果这样写那么那么上面的途中得到的就是xxxxxx了。
那么绑定就是这样了。
感谢你能够认真阅读完这篇文章,希望小编分享的“C#中WPF ListView绑定数据的示例分析”这篇文章对大家有帮助,同时也希望大家多多支持创新互联成都网站建设公司,关注创新互联成都网站建设公司行业资讯频道,更多相关知识等着你来学习!
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、网站建设公司香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
网页名称:C#中WPFListView绑定数据的示例分析-创新互联
新闻来源:http://www.scyingshan.cn/article/ccosso.html


咨询
建站咨询
