惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
www.infosecurity-magazine.com
www.infosecurity-magazine.com
L
LINUX DO - 最新话题
N
News | PayPal Newsroom
S
Security Affairs
W
WeLiveSecurity
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Webroot Blog
Webroot Blog
Spread Privacy
Spread Privacy
A
Arctic Wolf
T
Troy Hunt's Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
Cybersecurity and Infrastructure Security Agency CISA
T
Threat Research - Cisco Blogs
V2EX - 技术
V2EX - 技术
Scott Helme
Scott Helme
Google Online Security Blog
Google Online Security Blog
Schneier on Security
Schneier on Security
F
Fortinet All Blogs
U
Unit 42
爱范儿
爱范儿
腾讯CDC
S
Security @ Cisco Blogs
PCI Perspectives
PCI Perspectives
Hacker News - Newest:
Hacker News - Newest: "LLM"
Apple Machine Learning Research
Apple Machine Learning Research
C
CERT Recently Published Vulnerability Notes
Security Latest
Security Latest
Y
Y Combinator Blog
S
Schneier on Security
Cisco Talos Blog
Cisco Talos Blog
T
The Blog of Author Tim Ferriss
Hugging Face - Blog
Hugging Face - Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
IT之家
IT之家
K
Kaspersky official blog
Security Archives - TechRepublic
Security Archives - TechRepublic
博客园 - 聂微东
Cloudbric
Cloudbric
V
V2EX
H
Help Net Security
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
小众软件
小众软件
TaoSecurity Blog
TaoSecurity Blog
T
Tor Project blog
G
Google Developers Blog
人人都是产品经理
人人都是产品经理
GbyAI
GbyAI
MyScale Blog
MyScale Blog

博客园 - 张谊

[转]ubuntu下 手动安装 LAMP 和 JAVA环境 [转]ViewState的使用 [转]Working with user roles and permissions in SharePoint Object Model [原]SharePoint文档库上传文档 [原]SharePoint列表与文档库EventHandeler [转]ASP.NET缓存概念及其应用浅析 window.showModalDialog以及window.open用法简介 [原]欢迎加入QQ群 [转]Silverlight中调用远程Web Service的权限问题 [转]BeanUtils接口和类 [原]Commons- BeanUtils学习笔记 [转]Apache+Tomcat负载均衡及Session绑定的实现 [原]基于Caché多维数据库的SSH实现 [原]关于支付宝API开发的一点心得 [原]Oracle中列自增的方法 [原]Java反射示例 [原]JavaSocket实现广播聊天室 [转]翻译 一些很酷的.Net技巧 《生命如一泓清水》
[原]如何在Silverlight中使用WebService绑定DataGrid
张谊 · 2009-06-13 · via 博客园 - 张谊

Page.xaml


<UserControl x:Class="SilverlightApplication15.Page"
    xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:data
="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
    
>
    
<Grid x:Name="LayoutRoot" Background="White" Loaded="LayoutRoot_Loaded">
        
<data:DataGrid x:Name="dgrd_DataGrid" Margin="5" AutoGenerateColumns="False" >
            
<data:DataGrid.Columns>
                
<data:DataGridTextColumn Header="姓名" Width="150" 
                                         Binding
="{Binding UserName}">
                
</data:DataGridTextColumn>
                
<data:DataGridTextColumn Header="年龄" Width="150" 
                                         Binding
="{Binding UserAge}">
                
</data:DataGridTextColumn> "
            
</data:DataGrid.Columns>
        
</data:DataGrid>
    
</Grid>
</UserControl>

Page.xaml.cs


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 System.Collections.ObjectModel;namespace SilverlightApplication15
{
    
public partial class Page : UserControl
    {
        
public Page()
        {
            InitializeComponent();
            
        }
        
void GetUser()
        {
            UserService.Service1SoapClient userService 
= new SilverlightApplication15.UserService.Service1SoapClient();
            userService.GetUserCompleted 
+= new EventHandler<SilverlightApplication15.UserService.GetUserCompletedEventArgs>(userService_GetUserCompleted);
            userService.GetUserAsync();

        }

void userService_GetUserCompleted(object sender, SilverlightApplication15.UserService.GetUserCompletedEventArgs e)
        {
            
if (e.Error == null)
            {
                List
<UserTest> user = new List<UserTest>();
                ObservableCollection
<SilverlightApplication15.UserService.User> list = e.Result;
                
for (int i = 0; i < list.Count; i++)
                {
                    user.Add(
new UserTest
                    {
                        UserName 
= list[i].UserName,
                        UserAge 
= list[i].UserAge
                    });
                }
                
this.dgrd_DataGrid.ItemsSource = user;
            }
        }
private void LayoutRoot_Loaded(object sender, RoutedEventArgs e)
        {
            GetUser();
        }
      
    }
    
}

WebService中仅包含一个返回List<User>的GetUser();

PS:在Silverlight中并不包含DataGrid,如需使用,请引用System.Windows.Controls.Data

并且在Page.xaml中声明

xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"