Kunal-Chowdhury.com - Microsoft Technology Blog for developers and consumers

How to Implement a DependencyProperty?

DependencyProperty is set to enable declarative code to alter the properties of an object which reduces the data requirements by providing a more powerful notification system regarding the change of data in a very specific way. In .NET, there are two types of properties. One is the normal property & another is the DependencyProperty which has added functionality over the normal property.

Now, let us discuss on how to implement such DependencyProperty to give a powerful notification on data change:

First of all, implement the UserControl class from INotifyPropertyChanged interface:

public partial class MyUserControl : UserControl, INotifyPropertyChanged
    public event PropertyChangedEventHandler PropertyChanged;
    protected void OnPropertyChanged(string propertyName)
        if (PropertyChanged != null)
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));

Create your own normal Property, lets say the name of the property is “Caption”.

public string Caption

    get { return GetValue(CaptionProperty).ToString(); } 
    set { SetValue(CaptionProperty, value); }

Now, register the DependencyProperty to the CLR by calling the Register method by passing the property field that you used to store the data in earlier step:

public static readonly DependencyProperty CaptionProperty = DependencyProperty.Register("Caption", typeof(string), typeof(MyUserControl), new PropertyMetadata(string.Empty, OnCaptionPropertyChanged));

The name of the identifier field of the DependencyProperty will be same as you used in the property after appending “Property” at the end. In this example, our Property name is “Caption”, hence our identifier field name is “CaptionProperty”. Add the PropertyMetaData with default value & callback event handler within the Register method as mentioned in the above code. Mark the identifier as static & readonly so that this will be unique to the CLR.

Now, implement the OnCaptionPropertyChanged event handler:

private static void OnCaptionPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)

    MyUserControl myUserControl = dependencyObject as MyUserControl; 

private void OnCaptionPropertyChanged(DependencyPropertyChangedEventArgs e)
    txbCaption.Text = Caption;

The implementation of the DependencyProperty is complete. You can either call it from XAML:

<local:MyUserControl Caption="My First Dependency Property Example" />

or from Code behind:

MyUserControl myUserControl = new MyUserControl();
myUserControl.SetValue(MyUserControl.CaptionProperty, "My First Dependency Property Example");

How to add a Splash Screen to WPF application?

Splash Screens are always helpful while starting the application. At the time of loading application code & data from backend, it is always good to show a splash screen to the end user. It actually gives a look & feel of loading something and that time the user will see the first UI on his desktop. In .Net 3.5 SP1, this is really simple. Just do the following to add a simple basic splash screen to your application.

1. Create a PNG image & add it to your project. PNG images are better choice rather than BMP images because, they are lighter in size and you can also create a transparent PNG image.

2. Now right click on that image & click properties from the solution explorer of Visual Studio 2008 SP1.

3. Here you will find an option named “Build Action”. Select “SplashScreen” from the dropdown.

4. Save the project, build it & run the application.

Now you will see the image (Splash Screen) before rendering the actual application. After completion of rendering of the main window, the Splash Screen will automatically close. This way, it improves the startup experience of the WPF application.

How to create SSL certificate for Web Development?

Microsoft provides a tool named “MakeCert.exe” which helps us to create a temporary SSL Certificate for development environment. This tool comes with Visual Studio & also with Windows SDK. If you installed Visual Studio, you can find it in this location: “C:\Program Files\Microsoft Visual Studio <VERSION>\SmartDevices\SDK\SDKTools”. If you installed Windows SDK, you will get it here: “C:\Program Files\Microsoft SDKs\Windows\<VERSION>\Bin”.

Now open Command Console (“cmd.exe”) & change your current directory to one of the location specified above. Type the following in Command Prompt & hit enter:

makecert -b 01/01/2009 -e 01/01/2020 -n "CN=Developers" -pe -r -sk "Microsoft Cryptographic Provider" -ss "Microsoft Cryptographic Store" c:\developerCertificate.cer

This will create a test certificate (valid from 01/01/2009 to 01/01/2020) named “developerCertificate.cer” in your ‘C’ drive, which you can use for development environment. You can change the validity period by changing the begindate (-b) & expirydate (-e). You can also change all the parameters specified above.

Here is the list of the parameters mentioned above:

Parameter Description
-b Begin Date
-e Expiry Date
-n Certificate Subject Name
-pe Mark Generated Private Key as Exportable
-r Configures MakeCert to create a self-signed root certificate
-sk Subject’s Key Container Name
-ss Subject’s Certificate Store Name

What’s New in Silverlight 3?

Silverlight 3, though it is in beta stage, but it came up with lots of new features. Some of them are mentioned below:

  • Silverlight 3 now supports H.264 video formats & AAC audio formats. Now it also supports RAW audio/video pipeline
  • It now supports GPU Acceleration by adding a parameter (EnableGPUAcceleration = "true") in the Silverlight object
  • It now supports 3D functionalities. You can now add Perspective view to the element level
  • Various Effects has been introduced in Silverlight 3 using Pixel Shader API (e.g. Blur, DropShadow etc)
  • Various Animations (like: bouncing, transition) are now part of the Silverlight 3
  • A user can start a Silverlight out-of-browser "application" either by right-clicking on the Silverlight element or by clicking on a button within the application itself
  • Silverlight now supports custom dialogs. By using the SaveFileDialog you can now write contents outside the sandbox
  • It now supports local messaging across multiple silverlight plugins
  • XAP compression has been improved
  • Lots of new controls (like: DockPanel, WrapPanel, Label, ViewBox, TreeView, ExpanderControl, AutoCompleteBox) were added in this version. New controls in the Silverlight Toolkit are also available
  • DataPagination has been added in Silverlight 3
  • Using NavigationFramework you can now navigate to different view of the application. You can now integrate the browser back/forward functionalities with this framework
  • Binding of elements are now available by which you can update the UI without any code. Data validation in binding is also available in this release
  • AssemblyCaching is now available by which you can download the external assemblies only once & later you can use them from the cache. This will improve the application load time during next load
  • In Silverlight 3 Network monitoring API has been introduced, by which you can check whether the application is connected to the network or not
  • Now binary XML format is also supported in addition to the text XML which will improve the performance in the messaging area

Cheers :)

Silverlight 3 Beta1 released

Microsoft has released Silverlight 3 Beta 1, which is backward compatible with Silverlight 2. That means, you can run your existing Silverlight 2 applications in Silverlight 3 environment.

Here you will find some important links:

Silverlight 2 (Final) Released

Today Microsoft has released the Final Version of Microsoft Silverlight 2.

Here’s the expected final SDK, Expression, and Silverlight tools:

For more information's visit:

Migrating Silverlight 2 Beta to RC0

If you are migrating Silverlight applications that were created for the Silverlight 2 Beta 2 release or earlier to the final release of Silverlight 2, you are going to need to get the newest Silverlight 2 Tools for Visual Studio 2008 and recompile your project(s).

1. Get the newest version of Silverlight 2 Tools for Visual Studio 2008. You can get these tools from the SDK or online at Getting Started. You may have to uninstall any old tools before doing this install.

2. Open your old project (e.g. .csproj file). A dialog will come up notifying you that your project was created with an older version of Silverlight tools and asks you if you want to upgrade your project. Click the Yes button.

3. Open all of the HTML files and change:

· The Silverlight MIME type from application/x-silverlight-2-b1 or application/x-silverlight-2-b2 to application/x-silverlight-2.

· The Silverlight installation URL from http://go.microsoft.com/fwlink/?LinkID=108182 or http://go.microsoft.com/fwlink/?LinkID=115261 to http://go.microsoft.com/fwlink/?LinkID=124807.

When the XAP is served from a different domain than the host HTML page, Silverlight will validate that the MIME type (Content-Type response header) returned on the HTTP response is application/x-silverlight-app. You are required to add an entry for the Silverlight XAP MIME type to your .htaccess file — e.g. AddType application/x-silverlight-app xap.

Note IIS7 shipped with the right MIME type configurations for Silverlight XAPs. No action is required if you are using IIS7.

© 2008-2017 Kunal-Chowdhury.com - Microsoft Technology Blog for developers and consumers | Designed by Kunal Chowdhury
Back to top