Event Summary: Session on Silverlight at NED

Today, 20th August ’09, I delivered a session on Silverlight at NED University of Engineering and Technology. The event was organized by Microsoft Student Partner “Faraz” in collaboration with Microsoft Community Pakistan. The event was titled as “Silverlight, An overview” was attended by around 50 students majority of them were enrolled in BCIT program. The session provided students an overview of Silverlight and Expression Blend.

I would like to thank every single student for attending the session, I really enjoyed today and it was my honor to be at one of the finest University of Pakistan and I must appreciate the interest of students as well.

Following was the overall agenda of the session:

  • Background
  • Introduction to Silverlight
  • XAML & Hello World Demo
  • Expression Blend
  • Animations
  • Style and Control Templates – Demo
  • Media Support

The session begin with discussion on the User Experience and why we need Silverlight? Followed by the introduction of Silverlight and it’s version history, along with the benefits of Silverlight as compared to earlier technologies.

The students were demonstrated Silverlight project structure and a basic Hello World application using Visual Studio 2008 SP1 and Silverlight tools for Visual Studio. We also had some discussion on Silverlight architecture and classes that are available in Silverlight. We also saw the shapes and animation in Silverlight and how Expression blend helps us generating XAML. Finally we saw how Silverlight provides look-less controls and the way Control Templates and Styles provides us flexibility to give control a complete custom look and feel.

Once again, Thank you to those who attended the event and Thank you NED, Microsoft Student Partner (NED) and Microsoft Community Pakistan for inviting me and providing me an opportunity to speak on Silverlight 🙂

Those who attended the session, please take out few minutes to fill the feedback form here.

Real World Scenario


From time to time, I receive emails from software developers around the world, specially from Middle East and Asia region, discussing some technical issue. So while I was answering an email today, I thought that it would be great if I create a category “Real World Scenario” on my blog and post the solution there so that many others could benefit.

But first please note some points 🙂

  • Being an MVP doesn’t mean that I know everything 🙂 but I will try my level best to help you in providing solution
  • The solution may not be the best approach to solve a particular problem or there may be a better way to code
  • Also, I may not post the exact question and code asked from person but will create question of similar situation otherwise I need to get permission from that person first

So this is my first post on the series of Real World Scenario.

Scenario: Binding a ComboBox to a Generic List of Custom class A with Display member as another class B exposed as public property in class A

Consider the following code snippet below:

public class B
    public string Info { get; set; }
    public int Id { get; set; }
public class A
    public string Name { get; set; }
    public B Information { get; set; }

We created two classes A and B and added some automatic properties in them. Most of the time, we want to bind our ComboBox (let’s say comboBox1) with List and Display member as some primitive data type, something like:

//populate some data
A obj1OfA= new A { Name = "Test1" , Information=new B { Info= "Info Test 1", Id = 1} };
A obj2OfA= new A { Name = "Test2" , Information=new B { Info= "Info Test 2", Id = 2} };
//and bind the comboBox1 with A
comboBox1.DataSource = listOfA;
comboBox1.DisplayMember = "Name";

In the code snippet above, we initialized a generic list of class A and then we created two objects of A using object intializer, a feature of C# 3.0, and finally added the objects in list along with binding of list to combobox.

So that will do our job because Name is a public property of type string in class A and it will display in Name easily. The question was that when you want to set Display Member as Information like:

comboBox1.DataSource = listOfA;
comboBox1.DisplayMember = "Information";

it will not display appropriate data in the combo box and that will be something like


and that is not what we wanted to display. The reason is that it actually calls ToString method and that returns type name in case when display member is Information. So the solution is that you need to override ToString() method in the class B and return the desired data that you want to display. So let’s go ahead and change our class B:

public class B
    public string Info { get; set; }
    public int Id { get; set; }
    public override string ToString()
        return Info;

and now when we execute our code we will get appropriate output showing the value of Info property in class B bind to our combobox 🙂 That’s all !

Thank you for the email sent by you, The Developers. Interaction with community really gives me an opportunity to learn from you people as well and a chance to serve the community. Thank you once again! Have a fantastic time!