自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

淺析Silvelight中顯示多重數(shù)據(jù)模型集合

開發(fā) 后端
這里將介紹Silvelight中顯示多重數(shù)據(jù)模型集合,主要是通過DataForm組件的ItemsSource屬性支持這種做法,希望本文能對大家有所幫助。
Silvelight中顯示多重數(shù)據(jù)模型集合,在本例中可以對不同的數(shù)據(jù)模型集合數(shù)據(jù)信息的更新、刪除。***的效果圖也分為兩種不同的情況。

在使用DataForm進行單個數(shù)據(jù)的瀏覽時,有時候為了節(jié)省空間,我們可能需要在一個DataForm的數(shù)據(jù)源中放置由不同的數(shù)據(jù)模型集合所組成的數(shù)據(jù)集合。幸運的是,Silverlight的DataForm組件的ItemsSource屬性支持這種做法。下面我就為大家介紹如何操作。

實例說明

在這個例子中,我建立了名為Employee和Delivery的數(shù)據(jù)模型。為了對比,我使用了一個DataGrid組件,使它與DataForm使用相同的數(shù)據(jù)源。大家可以看看結果究竟有何不同。(見最終效果圖)

實例引申

該實例可以用作不同的數(shù)據(jù)模型集合數(shù)據(jù)信息的更新、刪除(可惜難以進行添加操作)。在為多重數(shù)據(jù)模型集合數(shù)據(jù)源進行各個數(shù)據(jù)模型的信息的添加時,記錄數(shù)據(jù)范圍。然后在進行更新或刪除時,根據(jù)這個范圍將多重數(shù)據(jù)模型集合數(shù)據(jù)源中object對象轉(zhuǎn)換成對應的數(shù)據(jù)模型后,再進行處理即可。

實例代碼

詳細的說明將在代碼中給出。

DataModel.cs數(shù)據(jù)模型代碼:

  1. using System;  
  2. namespace SilverlightClient  
  3. {  
  4.     public class Employee  
  5.     {  
  6.        public int EmployeeID { get; set; }  
  7.         public string EmployeeName { get; set; }  
  8.         public int EmployeeAge { get; set; }  
  9.     }  
  10.     public class Delivery  
  11.     {  
  12.         public int DeliveryID { get; set; }  
  13.         public string DeliveryFrom { get; set; }  
  14.         public string DeliveryTo { get; set; }  
  15.     }  

MainPage.xaml文件代碼:

  1. <UserControl 
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"   
  3.    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  4. xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"   
  5.     mc:Ignorable="d" xmlns:dataFormToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.DataForm.Toolkit" xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data" x:Class="SilverlightClient.MainPage" 
  6.     d:DesignWidth="320" d:DesignHeight="380"> 
  7.     <Grid x:Name="LayoutRoot" Width="320" Height="380" Background="White"> 
  8.         <dataFormToolkit:DataForm x:Name="dfDataModel" Margin="8,8,8,179"/> 
  9.         <!--用作對比的DataGrid組件--> 
  10.         <data:DataGrid x:Name="dgDataModel" Margin="8,252,8,8" Width="304" Height="120"/> 
  11.     </Grid> 
  12. </UserControl> 
  13. MainPage.xaml.cs文件代碼:  
  14. using System;  
  15. using System.Collections.Generic;  
  16. using System.Collections.ObjectModel;  
  17. using System.Linq;  
  18. using System.Net;  
  19. using System.Windows;  
  20. using System.Windows.Controls;  
  21. using System.Windows.Documents;  
  22. using System.Windows.Input;  
  23. using System.Windows.Media;  
  24. using System.Windows.Media.Animation;  
  25. using System.Windows.Shapes;  
  26. namespace SilverlightClient  
  27. {  
  28.     public partial class MainPage : UserControl  
  29.     {  
  30.         public MainPage()  
  31.        {  
  32.             InitializeComponent();  
  33.             this.Loaded += new RoutedEventHandler(MainPage_Loaded);  
  34.         }  
  35.        void MainPage_Loaded(object sender, RoutedEventArgs e)  
  36.         {  
  37.             dfDataModel.ItemsSource = GetHeterogeneousData();//提供數(shù)據(jù)源  
  38.             dgDataModel.ItemsSource = GetHeterogeneousData();//用作對比  
  39.         }  
  40.         private List<Employee> GetEmployees()//生成雇員信息  
  41.         {  
  42.             List<Employee> returnedValue = new List<Employee>();  
  43.             returnedValue.Add(new Employee() { EmployeeID = 1EmployeeName = "張三"EmployeeAge = 23 });  
  44.             returnedValue.Add(new Employee() { EmployeeID = 2EmployeeName = "李四"EmployeeAge = 24 });  
  45.             returnedValue.Add(new Employee() { EmployeeID = 3EmployeeName = "王五"EmployeeAge = 25 });  
  46.             return returnedValue;  
  47.         }  
  48.         private List<Delivery> GetDelivery()//生成遞送信息  
  49.        {  
  50.             List<Delivery> returnedValue = new List<Delivery>();  
  51.             returnedValue.Add(new Delivery() { DeliveryID = 1DeliveryFrom = "南京"DeliveryTo = "寧波" });  
  52.             returnedValue.Add(new Delivery() { DeliveryID = 2DeliveryFrom = "鎮(zhèn)江"DeliveryTo = "蘇州" });  
  53.             return returnedValue;  
  54.         }  
  55.         private ObservableCollection<object> GetHeterogeneousData()//為DataForm提供多重數(shù)據(jù)模型集合的數(shù)據(jù)源  
  56.         {  
  57.             ObservableCollection<object> returnedValue = new ObservableCollection<object>();  
  58.             GetEmployees().ForEach( x => returnedValue.Add(x));//向集合數(shù)據(jù)源中添加Employee數(shù)據(jù)信息  
  59.             GetDelivery().ForEach(x => returnedValue.Add(x));//向集合數(shù)據(jù)源中添加Delivery數(shù)據(jù)信息  
  60.             return returnedValue;  
  61.        }  
  62.     }  

最終效果圖

最終效果圖1
最終效果圖2

原文標題:有關DataForm組件的研究_顯示多重數(shù)據(jù)模型集合——Silverlight學習筆記[24]

鏈接:http://www.cnblogs.com/Kinglee/archive/2009/09/09/1563547.html

【編輯推薦】

  1. Office 2010將使用Silverlight改善用戶體驗
  2. 微軟.NET平臺主管談Silverlight企業(yè)級開發(fā)
  3. Flash與Silverlight多領域?qū)崪y對比
  4. 微軟宣稱Silverlight裝機量超過三億
  5. 圖解Silverlight 3的7個新功能
責任編輯:彭凡 來源: 博客園
相關推薦

2022-08-15 14:49:12

物聯(lián)網(wǎng)數(shù)據(jù)模型存儲

2010-05-26 14:37:56

Cassandra數(shù)據(jù)

2021-02-28 22:20:25

2009-09-18 14:07:51

LINQ to SQL

2012-03-05 10:54:03

NoSQL

2021-01-27 05:34:33

Python對象模型

2017-06-27 10:08:29

數(shù)據(jù)倉庫模型

2010-08-11 09:29:25

FlexJava數(shù)據(jù)模型

2016-11-02 12:32:47

數(shù)據(jù)分析大數(shù)據(jù)模型

2021-07-14 10:09:05

架構模型數(shù)據(jù)

2022-12-09 09:39:01

數(shù)據(jù)治理

2020-10-14 06:28:38

數(shù)據(jù)倉庫模型

2016-01-07 11:25:12

數(shù)據(jù)模型訓練數(shù)據(jù)

2009-11-12 16:39:02

ADO.NET實體數(shù)據(jù)

2009-07-20 14:14:03

PowerDesign

2024-11-15 11:43:21

2023-02-26 17:46:03

2021-01-15 13:18:39

數(shù)據(jù)模型領域模型代碼

2024-07-15 09:13:48

2022-11-15 08:21:49

物聯(lián)網(wǎng)數(shù)據(jù)模型Apache
點贊
收藏

51CTO技術棧公眾號