silverlight   发布时间:2022-05-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Silverlight 3 DataGrid 二大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

 MainPage.xaml Code: <UserControl xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data" x:Class="SilverlightApplication18.MainPage" xmlns="http://scheR_559_11845@as.micro

 MainPage.xaml Code:

@H_404_9@<UserControl xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data" x:Class="SilverlightApplication18.MainPage" xmlns="http://scheR_559_11845@as.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://scheR_559_11845@as.microsoft.com/winfx/2006/xaml" xmlns:d="http://scheR_559_11845@as.microsoft.com/expression/blend/2008" xmlns:mc="http://scheR_559_11845@as.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480"> <Grid x:Name="LayoutRoot"> <Grid HorizontalAlignment="Left" Width="4"/> <data:DataGrid Height="150" Margin="74,38,63,0" VerticalAlignment="Top" x:Name="dgperson"/> <ListBox Margin="74,212,206" x:Name="lbtxt"/> </Grid> </UserControl>

 MainPage.xaml.cs Code:

@H_404_9@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.ComponentModel; using System.Collections.ObjectModel; namespace SilverlightApplication18 { public class Person:INotifyPropertyChanged { private String fristname; public String Fristname { get { return fristname; } set { if (value != fristName) { fristname = value; OnPropertyChanged(this,"Fristname"); } } } private String lastname; public String Lastname { get { return lastname; } set { if (value != lastName) { lastname = value; OnPropertyChanged(this,"Lastname"); } } } private String fullname; public String Fullname { set { fullname = Fristname + Lastname; if (value != fullName) { value = fullname; OnPropertyChanged(this,"Fullname"); } } get { return (Fristname + lastName); } } public event PropertyChangedEventHandler PropertyChanged; void OnPropertyChanged(object sender,String value) { if (this.PropertyChanged != null) { PropertyChanged(sender,new PropertyChangedEventArgs(value)); } } } public partial class MainPage : UserControl { ObservableCollection<Person> GetPerson() { ObservableCollection<Person> objperson = new ObservableCollection<Person>(); objperson.Add(new Person { Fristname="churen",Lastname="youzi1"}); objperson.Add(new Person { Fristname = "churen2",Lastname = "youzi2" }); objperson.Add(new Person { Fristname = "churen3",Lastname = "youzi2" }); return objperson; } public ObservableCollection<Person> ObPerson; public MainPage() { InitializeComponent(); this.Loaded += new RoutedEventHandler(MainPage_Loaded); } void MainPage_Loaded(object sender,RoutedEventArgs E) { ObPerson = GetPerson(); this.dgperson.Itemssource = ObPerson; this.lbtxt.Itemssource = ObPerson; this.lbtxt.DisplaymemberPath = "Lastname"; } } }

实现效果

Silverlight 3 DataGrid 二

 

当DataGrid里面内容改变时候,LISTBox里面的内容自动改变,如图:

Silverlight 3 DataGrid 二

关于:ObservableCollection的资料解说

Silverlight 3 DataGrid 二

大佬总结

以上是大佬教程为你收集整理的Silverlight 3 DataGrid 二全部内容,希望文章能够帮你解决Silverlight 3 DataGrid 二所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。