2 Day Workshop on WPF for Faculty

Higher Education Commissions (HEC) and Microsoft Innovation Center (MIC) recently organized a 2 day workshop on Windows Presentation Foundation (WPF) for faculty and I was invited as trainer.

AdilWPF Workshop

The overall agenda of the 2 day workshop was to introduce Microsoft’s platform for building Windows client applications. The audience comprises of faculty from University of Karachi, NED UET, IBA, LUMHS etc. However, I consider it as an honor and opportunity for me to interact with the academia and share with them some of the current trends in technology and near future.

The best part was that we utilized our lunch and tea breaks as discussion forums where we discussed about Computer Science curriculum and how we can enable our students more to become better computer scientist, engineers and entrepreneurs. We also had discussion on where WPF fits in for computer science students.

It was really nice to interact with distinguished faculty members and I really enjoyed conducting the workshop.

Slides presented during the workshop are embedded below but I used whiteboard a lot during the workshop along with code demonstration using Visual Studio 2010 and so slides were merely for reference.

C# 4.0 + Visual Studio 2010 Beta + Windows 7 RC

Here we are with the Visual Studio 2010 Beta installed on Windows 7 RC, the most coolest and latest stuff out yet 🙂

In this post, I wanted to share some glimpse at Visual Studio 2010 beta along with some demonstration of one of the feature of C# 4.0 🙂 For Windows 7, I will write another detail post about the new features and what I like most and why it can be the best windows till yet!

So, coming back to VS 2010, If you start Visual Studio 2010 Beta, you will notice a major change in UI of Visual Studio with a nice, interactive and customizable startup page :

VS 2010 Beta Start up

Yes, It’s UI is built on Windows Presentation Foundation (WPF). So let’s go ahead and create a new project:

As you can see we have a similar kind of option, as in VS 2008, is available to select target framework version which is by default 4.0 🙂 and as you can see we have Silverlight templates available so now no need to install separate Silverlight 2 tools for VS :). Let’s move forward and create a new C# Console Application:

You will notice that editor itself is in WPF along with the intellisense menu but works almost as identical. So let’s try one of the feature of C# 4.0 🙂

I’m going to implement a method that takes dynamic typed object and that object will invoke a method which will be resolved at runtime!

DemoCSharpFeature

Didn’t get? Keep reading 🙂 Here we have a DemoCSharpFeature class that have a static method having a dynamic parameter “obj”. Now inside that method, I have written obj.ABC() which can be resolved only at runtime because at compile time, compiler does not know what will be the actual type and it will be resolved dynamically at runtime and hence compiler will not raise a compile time error here 🙂

I have created another DemoClass which have method ABC.

Main Method 

As you have noticed that I have created an object of DemoClass which contains method “ABC” and passed to CheckDynamicParameter. The demoObj parameter will be resolved at runtime and it will find ABC method in it. Thanks to dynamic type in C# 4.0, otherwise I would have used Reflection here or static typed object 🙂

Let’s hit F5!

image

The beauty is that even if I remove method ABC from DemoClass, the program will still compile because it will expect that when dynamic is resolved at runtime it will find the method ABC and if not found, a Runtime Binder Exception would raised.

That’s all for today! If you want to download Visual Studio 2010 Beta, visit Visual Studio on MSDN

Binding Enum to ComboBox

Hi,

Whether it’s Windows Forms or Windows Presentation Foundation While working with ComboBox, we usually want to bind any list as ComboBox Items.

For example,

//In windows forms
string[] names = { “Microsoft”, “IBM”, “Apple” };
cmbNames.DataSource = names;  //cmbNames is comboBox ID

or

//In windows presentation foundation
string[] names = { “Microsoft”, “IBM”, “Apple”};
cmbNames.ItemsSource = names;  //cmbNames is comboBox ID

That’s simple! But today I wanted to convert enum constants into an array of string and I wanted to make it ItemsSource of combo. So I created an enum type “Names” and tried that

public enum Names

    Microsoft, 
    IBM, 
    Apple
}

Names nameList;
cmbNames.ItemsSource = nameList ; //compile time error-

A compile time error is raised claiming that Cannot implicitly convert type ‘Names’ to ‘System.Collections.IEnumerable’. So i searched for that and find a good single line solution 🙂

//For WPF
cmbNames.ItemsSource = Enum.GetNames(typeof(Names));

//and In windows forms
cmbNames.DataSource = Enum.GetNames(typeof(Names));

It will convert enum contants into string[]. To convert back from string to constant you can use Enum.Parse(…).

Nice Feature! Isn’t it?