Sunday, September 28, 2008

Lap around Silverlight 2 RC

Well, I am getting addict to Silverlight these days, don’t know why but it keep pulling me away from my main domain ASP.NET.

Yesterday I spend my whole day on Silverlight, since Friday went in just reading news about upcoming Pre-beta release of Windows 7 at PDC and release of Silverlight 2 RC.

So we have to welcome 3 new members to our Silverlight team :)

1.Password Box  2. Combo Box  and  3. ProgressBar

Well, what amaze me is to have separate control as “PasswordBox”, it could have been say TextBox having two properties as Type and Password char like we have for Server control TextBox in ASP.NET, well since I am small developer Pune..who gonna listen me.. :)

XAML declaration of these 3 fellow friends looks like :

<PasswordBox x:Name="Pwd" Height="20" Width="100" />

<ComboBox x:Name="cmbUGLeads" DisplayMemberPath="FirstName" Height="20" Width="150" />

<ProgressBar x:Name="Prgs" BorderBrush="Azure" Height="20" Width="100" SmallChange="1" Value="0" >


Well don’t get stunned by “DisplayMemberPath” property in ComboBox, this is use to bind the data to ComboBox.Rest for ProgressBar and PasswordBar all the properties are same that we use to have in ASP.NET controls.

What I observe yesterday while installing Silverlight 2 RC is smooth hassle free installation without any demands from user except it ask to close your all browser instances.[Big Thanks to Microsoft for this !], well for my friends who are in love of doing things in Blend, they need to install Blend 2.0 with SP so you need to say good bye to Blend 2.5 preview for a while.

Here is small demo which loads media element in combobox at runtime and offcourse media element is also getting generated at runtime.

XAML Code for this :

<Grid x:Name="LayoutRoot" Background="White">

        <ComboBox x:Name="cmbUGLeads" Height="20" Width="150" />     


C# Code for this :

public SLRCDemo()
            this.Loaded += new RoutedEventHandler(SLRCDemo_Loaded);

        void SLRCDemo_Loaded(object sender, RoutedEventArgs e)

        public void GetMedia()
            MediaElement med1 = new MediaElement();
            med1.Source = new Uri("/Video01.wmv", UriKind.Relative);
            med1.AutoPlay = true;
            med1.Height = 50;
            med1.Width = 50;

            MediaElement med2 = new MediaElement();
            med2.Source = new Uri("/Video02.wmv", UriKind.Relative);
            med2.AutoPlay = true;
            med2.Height = 50;
            med2.Width = 50;



And output will be 2 nice videos in your Combo once you click on ComboBox.


Well, Another demo I created from ScottGu’s Blog [ He is really a Guru in Web Technologies like ASP.NET and MVC], This is using List<> and bind to Combo, here you can see I am making use of “DisplayMemberPath”, well code for this demo, simple thing you just need one class and few properties and you are done with it.

XAML Code :

<Grid x:Name="LayoutRoot" Background="White">
        <ComboBox x:Name="cmbUGLeads" DisplayMemberPath="FirstName" Height="20" Width="150" />

C# Code : [*Note : this.Loaded will work like Page_Load in ASP.NET]

public SLRCDemo()
            this.Loaded += new RoutedEventHandler(SLRCDemo_Loaded);
        void SLRCDemo_Loaded(object sender, RoutedEventArgs e)

        public void GetUGLeads()
            List<UGLeads> Leads = new List<UGLeads>();
            Leads.Add(new UGLeads() { FirstName = "Vikram", LastName = "Pendse" });
            Leads.Add(new UGLeads() { FirstName = "Mayur", LastName = "Tendulkar" });
            Leads.Add(new UGLeads() { FirstName = "Mahesh", LastName = "Mitkari" });
            Leads.Add(new UGLeads() { FirstName = "Sarang", LastName = "Datye" });
            cmbUGLeads.ItemsSource = Leads;

public class UGLeads
        public string FirstName { get; set; }
        public string LastName { get; set; }

So, Hope rather I am sure now will go ahead and download Silverlight 2 RC and start building great applications.Meanwhile let me complete another interesting demo on media element and Ink, I will soon post them here but they are in Silverlight 2 beta 2.


Sunday, September 21, 2008

Dynamic Data Web Application with ASP.NET 3.5

Just saw VTD [ Virtual Tech Days ] is coming with a boom. Loads of new stuffs and frameworks getting added day after day.Really a confusion state sometime to learn and implement simply because each one is unique and dependent on something, so no option but is to learn.

Well, I spend whole day with Dynamic Data today [ This was so exciting that I forget to have coffee in afternoon ;-) ]

First you need to understand What is Dynamic Data??, well answer you can get on site and some other forums or even on wiki. What you need to do it and learn it is to have .NET framework 3.5 SP and Visual Studio 2008 SP installed on your machine, VS08 SP do comes with .net 3.5 SP, so relax and just do this one installation. This will add Dynamic Data Site template along with another hot technology Entitiy Framework.


You need to select Dynamic Data Web Application since Dynamic Data Entities Web Application belongs to ADO.NET Entity framework and what we are doing is to implement it with LINQ to SQL. Once you create new site, you will have following structure which is quite big and confusing for first time.


You can see lots of folders are there, out of which we are mostly doing things with “Field Templates” and “Page Templates”, Filed Templates provided to have different data types and Page Templates are provided to have all the necessary functions on data like Gird and Detail view to do DML operations on data which is getting from LINQ to SQL.

Now next step is to implement LINQ To SQL, So add a new context to your project just like you do in day to day LINQ to SQL.


I will now add NorthwindDataContext to my project and simply drag and drop the tables on page which I want, similar as we do in LINQ to SQL. Then once we done with that then the real thing of Dynamic Data starts, First go to Global.asax file and do modifications in that like passing the correct Contextname etc.


we need to write following code there as :

model.RegisterContext(typeof(NorthWindDataContextDataContext),new ContextConfiguration()

{ScaffoldAllTables = true});

You can read more about MetaModel on MSDN, here we are creating instance of MetaModel. Else what ever routing part is there with other config. that I will share in my upcoming article on Dynamic Data.

Now simply Run the application, I have done rather I tried my best to edit some of its core design, soon i will implement my own CSS to Grid etc. but first output will be list of tables in that particular context.I added few lables to it and binded with count of tables from that particular context.


Once you select particular Table you will be then thrown to Grid layout :


You can see the Grid with built-in Templates for Edit,Delete and Details view along with Pagination.

Typical Edit Mode :


So, you can Edit and Update the same or even you can delete reocords too, You too have facility to insert records that too with Validations, you have <asp:DynamicValidator> control got introduce which is especially for Dynamic Data and it do work like normal validation controls we have normally. so its only for specific purpose. So this is how all the DML is getting managed automatically in Dynamic Data without writing much of code. this is unique to build rapid web applications with less time span spending on development.


Well.This is all about Dynamic Data, you are ready with your first application on Dynamic Data using ASP.NET 3.5, I will soon come with more information on this,but this will be a good healthy start for us to move ahead in Dynamic Data Web Application arena.

One more thing, before ending this article is that if you by chance have made ScaffoldAllTables = false in Global.asax file.


Second block shows the throw where the error will get thrown if  ScaffoldAllTables attribute is false, so make it true and run the application, Also first block is showing how i added table count to this application.

So this is how one can go ahead and build rich Dynamic Data Web Application within no time. I will soon be here with more Dynamic Data related information.


Saturday, September 6, 2008

Desklighter : Silverlight on Desktop as Windows Application

I had my session recently on Silverlight 2.0 at Annual DevCon-Developer's Conference in Pune, It went very well and I got good feedback too.

Well, Then onwards,rather these days, Silverlight is really pulling me towards it and I am really spending my all free time to explore and do more hands on Silverlight.

Today I found a brilliant tool on net while reading various articles on Internet.

This revolutionary tool is "Desklighter", a free download tool which I believe is Magic !! , It converts your web based Silverlight application to Standard EXE for Windows, So you can now run your Silverlight Web application on Windows by just double clicking the EXE !!

Do you think I am fooling you? then go ahead and check the link below:

Download it !! Right now !!..Its free and great tool to have.

I tried out converting my Ink Application which I have already blogged about. So what I did just installed this Desklight and given them my XAP file as input and by just a single click it turned into EXE !


Once you download and extract the setup, you will have one EXE and a sample XAP file , just run that EXE and give the XAP path to it like below :


Once you click on Convert, Then it will show you a message if the operation is successful. And then you can run that EXE, as I said earlier it worked for me for my Ink Application, still you think I am joking?


So, download this tool and check it out ! How XAP input give EXE of Silverlight Web Appication, worth trying out.