1.默认数据显示(自动显示列)

后台绑定

            //DataGrid 数据绑定
dataGridOne.ItemsSource = _Context.Info.ToList();

前台定义

        <DataGrid Name="dataGridOne"
HorizontalAlignment="Left" Margin="10,92,0,0"
VerticalAlignment="Top" Height="219"
Width="642"/>

结果显示:

2.自定义显示列,DataGrid.AutoGenerateColumns 只是是否产生自动列

后台绑定同上

前台定义:

        <DataGrid  Grid.Row="1" AutoGenerateColumns="False"
x:Name="dataGridOne" Margin="20,20,20,20" >
<DataGrid.Columns>
<DataGridTextColumn Header="编号" Binding="{Binding Code}"/>
<DataGridTextColumn Header="姓名" Binding="{Binding Name}"/>
<DataGridTextColumn Header="性别" Binding="{Binding Sex}"/>
<DataGridTextColumn Header="民族" Binding="{Binding Nation}"/>
<DataGridTextColumn Header="生日" Binding="{Binding Birthday}"/>
</DataGrid.Columns>
</DataGrid>

结果显示:

 3.自定义链接列显示

后台代码:

        private void Button_Click(object sender, RoutedEventArgs e)
{
//数据绑定
dataGridOne.ItemsSource = list;
}
public class UrlItem
{
public string Name { get; set; }
public int SortNumber { get; set; }
public string Url { get; set; }
}

前台定义:

        <DataGrid x:Name="dataGridOne"
AutoGenerateColumns="False"
AlternatingRowBackground="PaleGoldenrod"
ColumnWidth="100" HorizontalAlignment="Left" Margin="15,15,0,0"
Grid.Row="1" VerticalAlignment="Top" Height="173" Width="518"
CanUserAddRows="False"
>
<DataGrid.Columns>
<DataGridTextColumn Header="网站名称" Binding="{Binding Name}" IsReadOnly="True"/>
<DataGridTextColumn Header="网址" Binding="{Binding Url}"/>
<DataGridTextColumn Header="序号" Binding="{Binding SortNumber}"/>
<DataGridHyperlinkColumn Header="查看" Binding="{Binding Url}" Width="200"/>
</DataGrid.Columns>
</DataGrid>

显示结果:

DataGrid 简单数据绑定实例1的更多相关文章

  1. DataGrid简单数据绑定实例2

    1.Image列显示: 后台绑定: //获取文件夹下的图片 string path = @"K:\Picture\jpg"; private void Button_Click(o ...

  2. WPF DataGrid 之数据绑定--实例2

    1.前台Grid定义 <!--数据绑定--> <DataGrid Grid.Row="1" Name="gridOne" Margin=&qu ...

  3. EasyUI DataGrid分页数据绑定

    记录东西感觉很痛苦,总结东西很痛苦,麻烦,不过为了下次的方便和知识的牢固以后要坚持总结. EasyUI DataGrid分页数据绑定 在解决方案中新建两个文件FormMain.aspx(html也可以 ...

  4. 【翻译】使用Knockout, Web API 和 ASP.Net Web Forms 进行简单数据绑定

    原文地址:http://www.dotnetjalps.com/2013/05/Simple-data-binding-with-Knockout-Web-API-and-ASP-Net-Web-Fo ...

  5. ASP.NET MVC 4 插件化架构简单实现-实例篇

    先回顾一下上篇决定的做法: 1.定义程序集搜索目录(临时目录). 2.将要使用的各种程序集(插件)复制到该目录. 3.加载临时目录中的程序集. 4.定义模板引擎的搜索路径. 5.在模板引擎的查找页面方 ...

  6. Linux简单程序实例(GNU工具链,进程,线程,无名管道pipe,基于fd的文件操作,信号,scoket)

    一, GNU工具链简介: (1)编译代码步骤: 预处理 -> 编译 -> 汇编 -> 链接: 预处理:去掉注释,进行宏替换,头文件包含等工作: gcc -E test.c -o te ...

  7. Redis:安装、配置、操作和简单代码实例(C语言Client端)

    Redis:安装.配置.操作和简单代码实例(C语言Client端) - hj19870806的专栏 - 博客频道 - CSDN.NET Redis:安装.配置.操作和简单代码实例(C语言Client端 ...

  8. Knockout, Web API 和 ASP.Net Web Forms 进行简单数据绑定

    使用Knockout, Web API 和 ASP.Net Web Forms 进行简单数据绑定   原文地址:http://www.dotnetjalps.com/2013/05/Simple-da ...

  9. MVC 4 插件化架构简单实现实例篇

    ASP.NET MVC 4 插件化架构简单实现-实例篇   先回顾一下上篇决定的做法: 1.定义程序集搜索目录(临时目录). 2.将要使用的各种程序集(插件)复制到该目录. 3.加载临时目录中的程序集 ...

随机推荐

  1. 单点登录CAS使用记(四):为登录页面加上验证码

    CAS默认的登录页面样式如下,只有用户名与密码两项验证项目. 现在需要为首页登录加上验证码功能. 第一步:首页对默认登录页面的样式进行了调整,使其看上去还算美观. 在页面上加上了验证码项目. 第二步: ...

  2. 多线程09-Lock和Condition

    1.概念 Lock比传统线程模型中的synchronized方式更加面向对象,与生活中的锁类似,锁本身也应该是一个对象.两个线程执行的代码片段要实现同步互斥的效果,它们必须用同一个Lock对象. 2. ...

  3. webApi项目中的问题

    1.场景:客户端调用API获取所有品牌列表,使用redis存储,第一次是获取全部,之后会增量获取,通过lasttime参数 出现的问题:redis连接超时,网络流量太大 原因:这个借口没做本地缓存,每 ...

  4. 企业管理系统开发笔记(4)---后台登录_MVC过滤器

    在asp.net时代,我们通常需要在后台的每个页面进行判断用户是否登录的状态,不管是通过session还是通过windows身份验证还是表单验证方式等等方法来对用户登录进行判断跳转.但是在mvc时代, ...

  5. javascript 滚动条下拉导航fixed

    <!doctype html> <html> <style> body{ margin:; padding:; } #top{ background:#; widt ...

  6. template of class

    class template will call the constructor of its member object before constructor itself......

  7. 不要if else的编程

    http://news.cnblogs.com/n/194216/ 英文原文:Unconditional Programming ] 本文作者介绍 Michael Feathers Michael F ...

  8. CentOS下安装postgresql

    一.说明 postgresql版本:9.4.1 安装包: postgresql94-server-9.4.1-1PGDG.rhel6.x86_64.rpm postgresql94-libs-9.4. ...

  9. Boost 和 STL 相比有哪些优势和劣势?

    1. 在设计原则上,STL和Boost大体统一因为STL和Boost基本上都是标准委员会那批人在策划.审核和维护,所以口味上是相对接近的.但是因为Boost并不在标准中,或者说是下一代标准的试验场,所 ...

  10. 用Setup系列函数完成驱动卸载安装[驱动安装卸载程序]

    // InstallWDFDriver.cpp : Defines the entry point for the console application. // #include "std ...