.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> Silverlight >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Designing RIA Silverlight Applications using Expression Blend - Part 2

Posted By:Mahadesh Mahalingappa       Posted Date: August 14, 2011    Points: 200    Category: Silverlight    URL: http://www.dotnetspark.com  

In this article let us check out how to bind the listbox to an objectdatasource in Silverlight using Expression Blend
 

In the first few Designing RIA Applications using Expression Blend - Part 1 would give a brief of how we are going to use those features.
 
In this article let us check out how to bind the listbox to an objectdatasource.
 
Lets create a new Blend Silverlight Application.

blend silverlight application
 
First and foremost lets create out classes as shown below : 
 
 
public class Employee: INotifyPropertyChanged
	{
		public Employee(string name, int id, bool current)
		{
			_name = name;
			_empID = id;
			_isCurrentEmployee = current;
			 
		}
		private string _name = string.Empty;
		private int _empID = 0;
		private bool _isCurrentEmployee;
		public string Name 
		{
			get {return _name;}
			set {
				if (value != _name)
				{
				 _name = value;
					OnPropertyChanged(this, "Name");
				}
			}
		}
		
		public int EmpID
		{
		get { return _empID; }
		set { 
			if (value != _empID)
				{
				 _empID = value;
					OnPropertyChanged(this, "EmpID");
				}
		}
		}
			
		public bool IsCurrentEmployee
		{
		get { return _isCurrentEmployee;}
		set {
			if (value != _isCurrentEmployee)
				{
				 _isCurrentEmployee = value;
					OnPropertyChanged(this, "IsCurrentEmployee");
				}
			}
		}
			
		public event  PropertyChangedEventHandler PropertyChanged ;

    	private void  OnPropertyChanged( object  sender,  string  propertyName)
		{
         if  ( this .PropertyChanged != null )
			{
				PropertyChanged(sender, new  PropertyChangedEventArgs(propertyName)) ;
			}
    }

	}
	
	public class Employees
	{
		string _companyName;
		public string CompanyName
		{
			get { return "Fabrikam Inc.";}
			set { _companyName = value;}
		}
		public ObservableCollection EmployeeCollection
		{
		get {
			ObservableCollection _emplist = new ObservableCollection();
			_emplist.Add(new Employee("Joe Smith", 12343, false));
			_emplist.Add(new Employee("Mark Jones", 8555, true));
			_emplist.Add(new Employee("Jane Miller", 2377, true));
			_emplist.Add(new Employee("Suzy Day", 5885, true));
		return 	_emplist;
		}
		}
		
	}
 
Create a data source by clicking on the icon highlighted below :

silverlight blend application
 
Click on Create Object Data Source.

expression blend silverlight application
 
A Create Object Data Source Dialog appears. Make sure the Show all assemblies is checked.

datasource in silverlight application4.gif
 
Select the Employees class as our ObjectDataSource.

ObjectDataSource in blend application
 
The Data Window changes as shown below :

data in blend application
 
Simply drag and drop the EmployeeCollection into the Listbox. 

listbox in blend silverlight application
 
Well we are done. The ListBox gets updated with the data as shown below :

silverlight blend application
 
Happy coding.
 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend