Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to display multiple data model collections in Silvelight

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Today, the editor will show you how to display multiple data model sets in Silvelight. The knowledge points in this article are introduced in great detail. Friends who feel helpful can follow the editor to browse the content of the article, hoping to help more friends who want to solve this problem to find the answer to the problem. Let's learn more about "how to display multiple data model sets in Silvelight".

Multiple data model collections are displayed in Silvelight. In this case, the data information of different data model collections can be updated and deleted. The effect diagram of * * is also divided into two different situations.

When browsing individual data with DataForm, sometimes in order to save space, we may need to place data sets made up of different data model collections in a DataForm data source. Fortunately, the ItemsSource property of the DataForm component of Silverlight supports this approach. Now I will show you how to do it.

Example illustration

In this example, I built a data model called Employee and Delivery. For comparison, I used a DataGrid component that uses the same data source as DataForm. We can see how the results are different. (see final effect diagram)

Example extension

This instance can be used to update and delete data information from different data model collections (unfortunately, it is difficult to add). When adding information for each data model for a multiple data model collection data source, the data range is recorded. Then, when updating or deleting, the object objects in the multiple data model collection data source are transformed into the corresponding data model according to this scope, and then processed.

Instance code

Detailed instructions will be given in the code.

DataModel.cs data model code:

Using System; namespace SilverlightClient {public class Employee {public int EmployeeID {get; set;} public string EmployeeName {get; set;} public int EmployeeAge {get; set;}} public class Delivery {public int DeliveryID {get; set;} public string DeliveryFrom {get; set;} public string DeliveryTo {get; set;}

MainPage.xaml file code:

MainPage.xaml.cs file code: using System; using System.Collections.Generic; using System.Collections.ObjectModel; 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 Namespace SilverlightClient {public partial class MainPage: UserControl {public MainPage () {InitializeComponent (); this.Loaded + = new RoutedEventHandler (MainPage_Loaded);} void MainPage_Loaded (object sender, RoutedEventArgs e) {dfDataModel.ItemsSource = GetHeterogeneousData (); / / provide data source dgDataModel.ItemsSource = GetHeterogeneousData () / used to compare} private List GetEmployees () / / generate employee information {List returnedValue = new List (); returnedValue.Add (new Employee () {EmployeeID = 1, EmployeeName = "Zhang San", EmployeeAge = 23}); returnedValue.Add (new Employee () {EmployeeID = 2, EmployeeName = "Li Si", EmployeeAge = 24}) ReturnedValue.Add (new Employee () {EmployeeID = 3, EmployeeName = "Wang Wu", EmployeeAge = 25}); return returnedValue;} private List GetDelivery () / / generate delivery information {List returnedValue = new List (); returnedValue.Add (new Delivery () {DeliveryID = 1, DeliveryFrom = "Nanjing", DeliveryTo = "Ningbo"}) ReturnedValue.Add (new Delivery () {DeliveryID = 2, DeliveryFrom = "Zhenjiang", DeliveryTo = "Suzhou"}); return returnedValue;} private ObservableCollection GetHeterogeneousData () / / data source for providing multiple data model collections for DataForm {ObservableCollection returnedValue = new ObservableCollection (); GetEmployees () .ForEach (x = > returnedValue.Add (x)) / / add Employee data information GetDelivery () .ForEach (x = > returnedValue.Add (x)) to the collection data source; / / add Delivery data information return returnedValue;}} to the collection data source

Final effect picture

Thank you for reading, the above is the whole content of "how to display multiple data model sets in Silvelight". Let's get started. I believe that the editor will certainly bring you better quality articles. Thank you for your support to the website!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report