Silverlight 3 DataGrid简单数据绑定
2009-11-20 11:23
447 查看
新建一个Link To SQL类:
设置序列化模式:
新建一个web服务:代码如下
添加web服务:
右击:MainPage.xaml 选择在Expression Blend 中打开,拖一个DataGrid控件。代码如下
在MainPage.xaml.cs代码添加如下代码:
设置序列化模式:
新建一个web服务:代码如下
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; namespace SilverlightApplication8.Web { /// <summary> /// CustomerService 的摘要说明 /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。 // [System.Web.Script.Services.ScriptService] public class CustomerService : System.Web.Services.WebService { [WebMethod] public List<Customers> CustomerDetails() { CustomersDataContext customerContext = new CustomersDataContext(); return customerContext.Customers.ToList(); } } }
添加web服务:
右击:MainPage.xaml 选择在Expression Blend 中打开,拖一个DataGrid控件。代码如下
<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data" x:Class="SilverlightApplication8.MainPage" d:DesignWidth="640" d:DesignHeight="480"> <Grid x:Name="LayoutRoot"> <data:DataGrid Margin="54,40,23,190" x:Name="datagrid" AutoGenerateColumns="True" ItemsSource="{Binding}" > </data:DataGrid> </Grid> </UserControl>
在MainPage.xaml.cs代码添加如下代码:
using System; using System.Windows.Controls; using SilverlightApplication8.CustomerService; using System.Windows.Data; namespace SilverlightApplication8 { public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); CustomerService.CustomerServiceSoapClient customerClient = new CustomerService.CustomerServiceSoapClient(); customerClient.CustomerDetailsAsync(); customerClient.CustomerDetailsCompleted += new EventHandler<CustomerDetailsCompletedEventArgs>(customerClient_CustomerDetailsCompleted); } void customerClient_CustomerDetailsCompleted(object sender, CustomerDetailsCompletedEventArgs e) { if (e.Error == null) { datagrid.ItemsSource = e.Result; } } } }
相关文章推荐
- SilverLight中datagrid数据绑定的简单使用
- Silverlight实用窍门系列:5.绑定webService数据到DataGrid,设置DataGrid模板,模拟数据库数据的绑定【附带实例源码】
- Silverlight 4 DataGrid动态生成列及绑定数据
- silverlight数据绑定之DataGrid
- Silverlight数据绑定之DataGrid
- Silverlight Chart 综合运用(样式、多轴、数据绑定、点状图、线形图、DataGrid、Chart导出综合运用)
- SilverLight DataGrid 自定义列数据绑定 上下文代理器 DataContextProxy
- Silverlight中的DataGrid绑定数据
- Silverlight DataGrid 数据绑定鼠标移入到内容项时显示类似ToolTip提示文本
- 稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox
- silverlight 数据绑定简单示例(creating dynamic bindings)
- DataGrid 简单数据绑定实例1
- dropdownlist,datagrid数据绑定简单实现
- Silverlight之MVVM模式简单介绍项目(数据绑定)
- 上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox
- 通过 IDictionary对Silverlight DataGrid 进行动态数据绑定
- 【原创】有关Silverlight控件DataGrid的绑定数据后单元格单独复制的功能实现分析
- silverlight简单数据绑定1
- Silverlight 4 DataGrid动态生成列及绑定数据
- silverlight数据绑定之DataGrid-转载