<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://msdnbangladesh.net/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><title type="html">zahid&amp;#39;s blog</title><subtitle type="html" /><id>http://msdnbangladesh.net/blogs/zahid/atom.aspx</id><link rel="alternate" type="text/html" href="http://msdnbangladesh.net/blogs/zahid/default.aspx" /><link rel="self" type="application/atom+xml" href="http://msdnbangladesh.net/blogs/zahid/atom.aspx" /><generator uri="http://communityserver.org" version="4.1.31106.3070">Community Server</generator><updated>2009-03-20T05:17:53Z</updated><entry><title>Introducing Silverlight 4</title><link rel="alternate" type="text/html" href="/blogs/zahid/archive/2010/07/23/introducing-silverlight-4.aspx" /><id>/blogs/zahid/archive/2010/07/23/introducing-silverlight-4.aspx</id><published>2010-07-23T01:29:35Z</published><updated>2010-07-23T01:29:35Z</updated><content type="html">&lt;p&gt;In this post I am going to discuss about some basic things inside Silverlight project. When we start Silverlight the first thing we face is XAML (Extended Application Markup Language). So I am going to start form XAML which is pronounced as /ˈzæməl/.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;u&gt;XAML (Extended Application Markup Language)&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;It is a XML-based declarative language which was created by Microsoft is used to initialize structured values and objects. XAML file generally rendered by the Silverlight plug-in and displayed inside the browser window. When we compile silverlight projects, it will first converts XAML into BAML (Binary Application Markup Language) and then rendered in the web browser window. &lt;/p&gt;  &lt;p&gt;So let’s investigate a simple Silverlight 4 Project.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;To create a new Silverlight application project&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;1. Start Visual Studio 2010.&lt;/p&gt;  &lt;p&gt;2. Select File &amp;gt; New Project &lt;/p&gt;  &lt;p&gt;3. In the Installed Templates pane, expand the Visual C# node and select Silverlight. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://msdnbangladesh.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/zahid/clip_5F00_image0024_5F00_3F96E276.jpg"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="clip_image002[4]" border="0" alt="clip_image002[4]" src="http://msdnbangladesh.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/zahid/clip_5F00_image0024_5F00_thumb_5F00_265B3CA4.jpg" width="644" height="393" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;i&gt;Note: In the list of templates we see that there are Silverlight Application, Silverlight Business Application, Silverlight Navigation Application template. We will check all those one after another in this post.&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;4. In the list of templates, select Silverlight Application. &lt;/p&gt;  &lt;p&gt;5. Specify a name and a location for the application and then click OK.&lt;/p&gt;  &lt;p&gt;The New Silverlight Application dialog box appears as shown in the following illustration.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msdnbangladesh.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/zahid/clip_5F00_image001_5F00_4806C99B.jpg"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="clip_image001" border="0" alt="clip_image001" src="http://msdnbangladesh.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/zahid/clip_5F00_image001_5F00_thumb_5F00_478A70D9.jpg" width="603" height="484" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;6. From the Silverlight Version drop-down list, select the version of Silverlight. I have chosen Silverlight 4. Click OK.&lt;/p&gt;  &lt;p&gt;With is a few second, Visual Studio will create the Silverlight solution which will contain a Silverlight Project and one Web Application Project to host your Silverlight application. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://msdnbangladesh.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/zahid/clip_5F00_image0014_5F00_2F170B24.jpg"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="clip_image001[4]" border="0" alt="clip_image001[4]" src="http://msdnbangladesh.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/zahid/clip_5F00_image0014_5F00_thumb_5F00_291C1BF1.jpg" width="558" height="484" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Once done, you will see Visual Studio already created two XAML files (App.xaml &amp;amp; MainPage.xaml) inside the Silverlight Application project. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;MainPage.xaml&lt;/u&gt;&lt;/strong&gt; &lt;/p&gt;  &lt;p&gt;MainPage.xaml is the startpage for the Silverlight application. It is possible to modify this page as per our need or we can create a new one. Let’s look at it:&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:13fa500b-d302-4b89-a552-537a93b0d536" class="wlWriterEditableSmartContent"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background:#000080;color:#fff;font-family:Verdana, Tahoma, Arial, sans-serif;font-weight:bold;padding:2px 5px;"&gt;&lt;/div&gt; &lt;div style="background:#ddd;max-height:300px;overflow:auto;"&gt; &lt;ol style="background:#ffffff;margin:0 0 0 2.5em;padding:0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;UserControl&lt;/span&gt;&lt;span style="color:#ff0000;"&gt; x&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;:&lt;/span&gt;&lt;span style="color:#ff0000;"&gt;Class&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;SilverlightApplicationDemo.MainPage&amp;quot;&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;   &lt;span style="color:#ff0000;"&gt; xmlns&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;   &lt;span style="color:#ff0000;"&gt; xmlns&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;:&lt;/span&gt;&lt;span style="color:#ff0000;"&gt;x&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;   &lt;span style="color:#ff0000;"&gt; xmlns&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;:&lt;/span&gt;&lt;span style="color:#ff0000;"&gt;d&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;http://schemas.microsoft.com/expression/blend/2008&amp;quot;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;   &lt;span style="color:#ff0000;"&gt; xmlns&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;:&lt;/span&gt;&lt;span style="color:#ff0000;"&gt;mc&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;http://schemas.openxmlformats.org/markup-compatibility/2006&amp;quot;&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;   &lt;span style="color:#ff0000;"&gt; mc&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;:&lt;/span&gt;&lt;span style="color:#ff0000;"&gt;Ignorable&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;d&amp;quot;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;   &lt;span style="color:#ff0000;"&gt; d&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;:&lt;/span&gt;&lt;span style="color:#ff0000;"&gt;DesignHeight&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;300&amp;quot;&lt;/span&gt;&lt;span style="color:#ff0000;"&gt; d&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;:&lt;/span&gt;&lt;span style="color:#ff0000;"&gt;DesignWidth&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;400&amp;quot;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#a31515;"&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Grid&lt;/span&gt;&lt;span style="color:#ff0000;"&gt; x&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;:&lt;/span&gt;&lt;span style="color:#ff0000;"&gt;Name&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;LayoutRoot&amp;quot;&lt;/span&gt;&lt;span style="color:#ff0000;"&gt; Background&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;White&amp;quot;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#a31515;"&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Grid&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&lt;span style="color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;UserControl&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;App.xaml&lt;/u&gt;&lt;/strong&gt; &lt;/p&gt;  &lt;p&gt;In App.xaml file we can define application level resources (like styles, data templates and control templates).&lt;/p&gt;  &lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:548edcb9-0157-477f-a668-2cbddb04cd5c" class="wlWriterEditableSmartContent"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background:#000080;color:#fff;font-family:Verdana, Tahoma, Arial, sans-serif;font-weight:bold;padding:2px 5px;"&gt;&lt;/div&gt; &lt;div style="background:#ddd;max-height:300px;overflow:auto;"&gt; &lt;ol style="background:#ffffff;margin:0 0 0 2.5em;padding:0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Application&lt;/span&gt;&lt;span style="color:#ff0000;"&gt; xmlns&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot;&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;            &lt;span style="color:#ff0000;"&gt; xmlns&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;:&lt;/span&gt;&lt;span style="color:#ff0000;"&gt;x&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;&lt;/span&gt; &lt;/li&gt; &lt;li&gt;            &lt;span style="color:#ff0000;"&gt; x&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;:&lt;/span&gt;&lt;span style="color:#ff0000;"&gt;Class&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;SilverlightApplicationDemo.App&amp;quot;&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;            &lt;span style="color:#0000ff;"&gt; &amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#a31515;"&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Application.Resources&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;        &lt;span style="color:#a31515;"&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Style&lt;/span&gt;&lt;span style="color:#ff0000;"&gt; x&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;:&lt;/span&gt;&lt;span style="color:#ff0000;"&gt;Key&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;btnStyle&amp;quot;&lt;/span&gt;&lt;span style="color:#ff0000;"&gt; TargetType&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;Button&amp;quot;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#a31515;"&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Setter&lt;/span&gt;&lt;span style="color:#ff0000;"&gt; Property&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;Background&amp;quot;&lt;/span&gt;&lt;span style="color:#ff0000;"&gt; Value&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;Yellow&amp;quot;/&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    &lt;span style="color:#a31515;"&gt;        &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Style&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#a31515;"&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Application.Resources&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&lt;span style="color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Application&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;The code-behind (App.xaml.cs) is used to handle application level events such as &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.application.startup%28VS.95%29.aspx" target="_blank"&gt;&lt;font color="#0000ff"&gt;Startup&lt;/font&gt;&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.application.exit%28VS.95%29.aspx" target="_blank"&gt;&lt;font color="#0000ff"&gt;Exit&lt;/font&gt;&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.application.unhandledexception%28VS.95%29.aspx" target="_blank"&gt;&lt;font color="#0000ff"&gt;UnhandledException&lt;/font&gt;&lt;/a&gt;. The &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.application.rootvisual%28VS.95%29.aspx" target="_blank"&gt;&lt;font color="#0000ff"&gt;RootVisual&lt;/font&gt;&lt;/a&gt; is used to setup the startup Silverlight UserControl. This property needs to be set in the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.application.startup%28VS.95%29.aspx" target="_blank"&gt;&lt;font color="#0000ff"&gt;Startup&lt;/font&gt;&lt;/a&gt; event.&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:9dd0ae80-a934-4922-af4c-a61cc9df8369" class="wlWriterEditableSmartContent"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background:#000080;color:#fff;font-family:Verdana, Tahoma, Arial, sans-serif;font-weight:bold;padding:2px 5px;"&gt;&lt;/div&gt; &lt;div style="background:#ddd;max-height:400px;overflow:auto;"&gt; &lt;ol style="background:#ffffff;margin:0 0 0 2.5em;padding:0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;partial&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;App&lt;/span&gt; : &lt;span style="color:#2b91af;"&gt;Application&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;  {&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;      &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; App()&lt;/li&gt; &lt;li&gt;      {&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;          &lt;span style="color:#0000ff;"&gt;this&lt;/span&gt;.Startup += &lt;span style="color:#0000ff;"&gt;this&lt;/span&gt;.Application_Startup;&lt;/li&gt; &lt;li&gt;          &lt;span style="color:#0000ff;"&gt;this&lt;/span&gt;.Exit += &lt;span style="color:#0000ff;"&gt;this&lt;/span&gt;.Application_Exit;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;          &lt;span style="color:#0000ff;"&gt;this&lt;/span&gt;.UnhandledException += &lt;span style="color:#0000ff;"&gt;this&lt;/span&gt;.Application_UnhandledException;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;          InitializeComponent();&lt;/li&gt; &lt;li&gt;      }&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;      &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Application_Startup(&lt;span style="color:#0000ff;"&gt;object&lt;/span&gt; sender, &lt;span style="color:#2b91af;"&gt;StartupEventArgs&lt;/span&gt; e)&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;      {&lt;/li&gt; &lt;li&gt;          &lt;span style="color:#0000ff;"&gt;this&lt;/span&gt;.RootVisual = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;MainPage&lt;/span&gt;();&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;      }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;      &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Application_Exit(&lt;span style="color:#0000ff;"&gt;object&lt;/span&gt; sender, &lt;span style="color:#2b91af;"&gt;EventArgs&lt;/span&gt; e)&lt;/li&gt; &lt;li&gt;      {&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;      }&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;      &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Application_UnhandledException(&lt;span style="color:#0000ff;"&gt;object&lt;/span&gt; sender, &lt;span style="color:#2b91af;"&gt;ApplicationUnhandledExceptionEventArgs&lt;/span&gt; e)&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;      {&lt;/li&gt; &lt;li&gt;          &lt;span style="color:#008000;"&gt;// If the app is running outside of the debugger then report the exception using&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;          &lt;span style="color:#008000;"&gt;// the browser&amp;#39;s exception mechanism. On IE this will display it a yellow alert &lt;/span&gt;&lt;/li&gt; &lt;li&gt;          &lt;span style="color:#008000;"&gt;// icon in the status bar and Firefox will display a script error.&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;          &lt;span style="color:#0000ff;"&gt;if&lt;/span&gt; (!System.Diagnostics.&lt;span style="color:#2b91af;"&gt;Debugger&lt;/span&gt;.IsAttached)&lt;/li&gt; &lt;li&gt;          {&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;              &lt;span style="color:#008000;"&gt;// NOTE: This will allow the application to continue running after an exception has been thrown&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;              &lt;span style="color:#008000;"&gt;// but not handled. &lt;/span&gt;&lt;/li&gt; &lt;li&gt;              &lt;span style="color:#008000;"&gt;// For production applications this error handling should be replaced with something that will &lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;              &lt;span style="color:#008000;"&gt;// report the error to the website and stop the application.&lt;/span&gt;&lt;/li&gt; &lt;li&gt;              e.Handled = &lt;span style="color:#0000ff;"&gt;true&lt;/span&gt;;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;              &lt;span style="color:#2b91af;"&gt;Deployment&lt;/span&gt;.Current.Dispatcher.BeginInvoke(&lt;span style="color:#0000ff;"&gt;delegate&lt;/span&gt; { ReportErrorToDOM(e); });&lt;/li&gt; &lt;li&gt;          }&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;      }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;      &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; ReportErrorToDOM(&lt;span style="color:#2b91af;"&gt;ApplicationUnhandledExceptionEventArgs&lt;/span&gt; e)&lt;/li&gt; &lt;li&gt;      {&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;          &lt;span style="color:#0000ff;"&gt;try&lt;/span&gt;&lt;/li&gt; &lt;li&gt;          {&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;              &lt;span style="color:#0000ff;"&gt;string&lt;/span&gt; errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace;&lt;/li&gt; &lt;li&gt;              errorMsg = errorMsg.Replace(&lt;span style="color:#a31515;"&gt;&amp;#39;&amp;quot;&amp;#39;&lt;/span&gt;, &lt;span style="color:#a31515;"&gt;&amp;#39;&amp;#92;&amp;#39;&amp;#39;&lt;/span&gt;).Replace(&lt;span style="color:#a31515;"&gt;&amp;quot;&amp;#92;r&amp;#92;n&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515;"&gt;@&amp;quot;&amp;#92;n&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;              System.Windows.Browser.&lt;span style="color:#2b91af;"&gt;HtmlPage&lt;/span&gt;.Window.Eval(&lt;span style="color:#a31515;"&gt;&amp;quot;throw new Error(&amp;#92;&amp;quot;Unhandled Error in Silverlight Application &amp;quot;&lt;/span&gt; + errorMsg + &lt;span style="color:#a31515;"&gt;&amp;quot;&amp;#92;&amp;quot;);&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;          }&lt;/li&gt; &lt;li&gt;          &lt;span style="color:#0000ff;"&gt;catch&lt;/span&gt; (&lt;span style="color:#2b91af;"&gt;Exception&lt;/span&gt;)&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;          {&lt;/li&gt; &lt;li&gt;          }&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;      }&lt;/li&gt; &lt;li&gt;  }&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;u&gt;Other common uses of App.xaml.cs file are:&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;· This application is accessible via the global static variable &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.application.current%28VS.95%29.aspx" target="_blank"&gt;&lt;font color="#0000ff"&gt;Application.Current&lt;/font&gt;&lt;/a&gt;. You can cast this anywhere in your application.&lt;/p&gt;  &lt;p&gt;· Using the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.application.install%28VS.95%29.aspx" target="_blank"&gt;&lt;font color="#0000ff"&gt;Install&lt;/font&gt;&lt;/a&gt; method you can prompt the user to install the application Out-of-Browser.&lt;/p&gt;  &lt;p&gt;· The &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.application_methods%28VS.95%29.aspx" target="_blank"&gt;&lt;font color="#0000ff"&gt;CheckAndDownloadUpdateAsync&lt;/font&gt;&lt;/a&gt; method is used when the application is running out-of-browser to ensure that the .xap file is the latest.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Silverlight Navigation Application project&lt;/u&gt; &lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msdnbangladesh.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/zahid/clip_5F00_image0016_5F00_119141F3.jpg"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="clip_image001[6]" border="0" alt="clip_image001[6]" src="http://msdnbangladesh.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/zahid/clip_5F00_image0016_5F00_thumb_5F00_5F897B9B.jpg" width="420" height="484" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The Silverlight Navigation Template provides a rapid means of developing page-based web applications. The two primary controls in the System.Windows.Control.Navigation namespace are Frame and Page. The Frame control hosts a single Page control utilizes the Navigation APIs to allow the user to navigate between the pages. The Page control resembles the commonly used UserControl control to hold the contents of the respected page. The project generates the default template and files for a sample page-based application. The Views Folder has pre-generated pages (AboutPage, ErrorWindow, and HomePage).&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Silverlight Business Application&lt;/u&gt;&lt;/strong&gt; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://msdnbangladesh.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/zahid/SilverlightBusinessTemplate_5F00_5564B4A3.jpg"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="SilverlightBusinessTemplate" border="0" alt="SilverlightBusinessTemplate" src="http://msdnbangladesh.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/zahid/SilverlightBusinessTemplate_5F00_thumb_5F00_544C792C.jpg" width="393" height="772" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;If we investigate Silverlight Business Application Template we will find a new addition that is the User Authentication. That is login and logout functionality. If we run the application we will find Login is displayed. &lt;/p&gt;  &lt;p&gt;When we build Silverlight project, it will create the XAP file (SilverlightApplicationNavigationDemo.xap) and put it into the ClientBin directory of the web project. When the page loads it will pickup from the same location as the source you specified inside the aspx/html page.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;XAP&lt;/u&gt;&lt;/strong&gt; &lt;/p&gt;  &lt;p&gt;A .xap (pronounced as ZAP) file is a compiled compressed output of the Silverlight application. The file is actually a .zip file that contains all the files necessary for the application such as application manifest file, compiled output assembly and other resources.&lt;/p&gt;  &lt;p&gt;Silverlight Application (XAP) generally loads inside the ASPX or HTML pages pointing to the path to load the XAP. Web pages use the Silverlight components by loading the .xap files using the &amp;lt;object&amp;gt; tag. &lt;/p&gt;  &lt;p&gt;Below is a list of available parameters that can be passed to the Silverlight plug-in using the &lt;code&gt;&amp;lt;param&amp;gt;&lt;/code&gt; tag.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;   &lt;table border="1" cellspacing="0" cellpadding="0"&gt;&lt;tbody&gt;       &lt;tr&gt;         &lt;td valign="top" width="248"&gt;           &lt;p&gt;&lt;b&gt;Parameter&lt;/b&gt;&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="168"&gt;           &lt;p&gt;&lt;b&gt;Description&lt;/b&gt;&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="134"&gt;           &lt;p&gt;&lt;b&gt;Type&lt;/b&gt;&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="248"&gt;           &lt;p&gt;allowHtmlPopupWindow&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="168"&gt;           &lt;p&gt;Specifies whether the HtmlPage.PopupWindow method is allowed. Defaults to true for applications in the same domain, otherwise false.&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="134"&gt;           &lt;p&gt;Boolean&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="248"&gt;           &lt;p&gt;autoUpgrade&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="168"&gt;           &lt;p&gt;Specifies whether the plug-in should attempt to upgrade if minRuntimeVersion is newer than the current Silverlight version. Default is true.&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="134"&gt;           &lt;p&gt;Boolean&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="248"&gt;           &lt;p&gt;background&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="168"&gt;           &lt;p&gt;Plug-in background color. Default is null (white).&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="134"&gt;           &lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/cc838148%28VS.95%29.aspx"&gt;&lt;font color="#0000ff"&gt;Color with or without alpha (RGB, ScRGB)&lt;/font&gt;&lt;/a&gt;&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="248"&gt;           &lt;p&gt;enableAutoZoom&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="168"&gt;           &lt;p&gt;Indicates whether the host (for certain platforms) can invoke zoom behavior that increases the DPI. Default is true.&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="134"&gt;           &lt;p&gt;Boolean&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="248"&gt;           &lt;p&gt;enableCacheVisualization&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="168"&gt;           &lt;p&gt;Indicates whether to use a non-production analysis visualization mode, which shows areas of a page that are being GPU accelerated with a colored overlay. Default is false. &lt;b&gt;Do not use in production code.&lt;/b&gt;&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="134"&gt;           &lt;p&gt;Boolean&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="248"&gt;           &lt;p&gt;enableFramerateCounter&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="168"&gt;           &lt;p&gt;Indicates whether to display the current frame rate in the hosting browser&amp;#39;s status bar (IE/Win only). &lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="134"&gt;           &lt;p&gt;Boolean&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="248"&gt;           &lt;p&gt;enableGPUAcceleration&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="168"&gt;           &lt;p&gt;Indicates whether to use graphics processor unit (GPU) hardware acceleration for cached compositions, which potentially results in graphics optimization. (false by default)&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="134"&gt;           &lt;p&gt;Boolean&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="248"&gt;           &lt;p&gt;enablehtmlaccess&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="168"&gt;           &lt;p&gt;Specifies whether the plug-in has full access to the browser DOM. Defaults to true for applications in the same domain, otherwise false.&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="134"&gt;           &lt;p&gt;Boolean&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="248"&gt;           &lt;p&gt;enableNavigation&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="168"&gt;           &lt;p&gt;Indicates whether the hosted content in the Silverlight plug-in can use a HyperlinkButton to navigate to external URIs. Default is all.&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="134"&gt;           &lt;p&gt;all: the hosted content can use HyperlinkButton to navigate to any URI. &lt;/p&gt;            &lt;p&gt;none: the hosted content cannot use HyperlinkButton for navigation to an external URI. Relative URIs for internal navigation are still permitted.&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="248"&gt;           &lt;p&gt;enableRedrawRegions&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="168"&gt;           &lt;p&gt;Determines whether to visually indicate the areas of the plug-in that are being redrawn with each frame. This property is for performance tuning and visualization during development only; &lt;b&gt;do not specify it for any deployed Silverlight-based application.&lt;/b&gt; Default is false.&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="134"&gt;           &lt;p&gt;Boolean&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="248"&gt;           &lt;p&gt;initParams&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="168"&gt;           &lt;p&gt;User-defined string of parameters.&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="134"&gt;           &lt;p&gt;Comma separated &lt;i&gt;key=value&lt;/i&gt; pairs&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="248"&gt;           &lt;p&gt;maxframerate&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="168"&gt;           &lt;p&gt;Specifies the maximum number of frames per second that the plug-in can render. The default is 60.&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="134"&gt;           &lt;p&gt;Integer&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="248"&gt;           &lt;p&gt;minRuntimeVersion&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="168"&gt;           &lt;p&gt;Specifies the earliest version of the Silverlight plug-in required.&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="134"&gt;           &lt;p&gt;Version number&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="248"&gt;           &lt;p&gt;onError&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="168"&gt;           &lt;p&gt;Error handler for parse and native code run-time errors.&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="134"&gt;           &lt;p&gt;JavaScript function name&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="248"&gt;           &lt;p&gt;onFullScreenChanged&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="168"&gt;           &lt;p&gt;Function to call when the FullScreen property changes.&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="134"&gt;           &lt;p&gt;JavaScript function name&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="248"&gt;           &lt;p&gt;onLoad&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="168"&gt;           &lt;p&gt;Function to call when the plug-in has finished loading in the DOM.&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="134"&gt;           &lt;p&gt;JavaScript function name&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="248"&gt;           &lt;p&gt;onResize&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="168"&gt;           &lt;p&gt;Function to call when the plug-in size changes.&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="134"&gt;           &lt;p&gt;JavaScript function name&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="248"&gt;           &lt;p&gt;onSourceDownloadComplete&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="168"&gt;           &lt;p&gt;Function to call when the source download has completed.&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="134"&gt;           &lt;p&gt;JavaScript function name&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="248"&gt;           &lt;p&gt;onSourceDownloadProgressChanged&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="168"&gt;           &lt;p&gt;Function to call when the source download progress changes.&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="134"&gt;           &lt;p&gt;JavaScript function name&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="248"&gt;           &lt;p&gt;onZoom&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="168"&gt;           &lt;p&gt;Specifies the handler for a Zoomed event that occurs when the Silverlight plug-in content area receives a host-generated zoom event. &lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="134"&gt;           &lt;p&gt;JavaScript function name&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="248"&gt;           &lt;p&gt;source&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="168"&gt;           &lt;p&gt;Specifies the address or relative path of either an initial XAML file or XAP.&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="134"&gt;           &lt;p&gt;URI&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="248"&gt;           &lt;p&gt;splashScreenSource&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="168"&gt;           &lt;p&gt;Specifies a XAML page to use as the splash screen. &lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="134"&gt;           &lt;p&gt;URI&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="248"&gt;           &lt;p&gt;windowless&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="168"&gt;           &lt;p&gt;Specifies the rendering mode for the plug-in for Windows versions of Silverlight. The default is false.&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="134"&gt;           &lt;p&gt;Boolean&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;     &lt;/tbody&gt;&lt;/table&gt; &lt;/p&gt;  &lt;p&gt;Here is the object tag :&lt;/p&gt;  &lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:92d9dbbf-d7d5-47c1-ab46-130b0f8045cd" class="wlWriterEditableSmartContent"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background:#000080;color:#fff;font-family:Verdana, Tahoma, Arial, sans-serif;font-weight:bold;padding:2px 5px;"&gt;&lt;/div&gt; &lt;div style="background:#ddd;max-height:300px;overflow:auto;"&gt; &lt;ol style="background:#ffffff;margin:0 0 0 2.5em;padding:0 0 0 5px;"&gt; &lt;li&gt;  &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;object&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;data&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;data:application/x-silverlight-2,&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;type&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;application/x-silverlight-2&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;width&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;100%&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;height&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;100%&amp;quot;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;          &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;param&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;name&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;source&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;value&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;ClientBin/SilverlightApplicationNavigationDemo.xap&amp;quot;/&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;          &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;param&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;name&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;onError&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;value&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;onSilverlightError&amp;quot;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;/&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;          &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;param&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;name&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;background&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;value&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;white&amp;quot;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;/&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;          &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;param&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;name&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;minRuntimeVersion&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;value&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;4.0.50401.0&amp;quot;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;/&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;          &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;param&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;name&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;autoUpgrade&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;value&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;/&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;          &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;a&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;href&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;http://go.microsoft.com/fwlink/?LinkID=149156&amp;amp;v=4.0.50401.0&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;style&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;&lt;/span&gt;&lt;span style="color:#ff0000;"&gt;text-decoration&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;:none&amp;quot;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;               &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;img&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;src&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;http://go.microsoft.com/fwlink/?LinkId=161376&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;alt&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;Get Microsoft Silverlight&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;style&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;&lt;/span&gt;&lt;span style="color:#ff0000;"&gt;border-style&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;:none&amp;quot;/&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;          &lt;span style="color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#800000;"&gt;a&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;        &lt;span style="color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#800000;"&gt;object&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;iframe&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;id&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;_sl_historyFrame&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;style&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;&lt;/span&gt;&lt;span style="color:#ff0000;"&gt;visibility&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;:hidden;&lt;/span&gt;&lt;span style="color:#ff0000;"&gt;height&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;:0px;&lt;/span&gt;&lt;span style="color:#ff0000;"&gt;width&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;:0px;&lt;/span&gt;&lt;span style="color:#ff0000;"&gt;border&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;:0px&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#800000;"&gt;iframe&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#800000;"&gt;div&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&lt;/p&gt; &lt;strong&gt;&lt;/strong&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;em&gt;Note: the iframe element is here for cross-browser compatibility. &lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Summery&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;In the above post I have tried to integrate all the information related Silverlight Application in one place so that a beginner could get a general overview. Maybe I have missed lots of information. If anyone one would like to add anything please feel free to leave your comments. In the next post I will try to explore Silverlight Layout System.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msdnbangladesh.net/aggbug.aspx?PostID=156691" width="1" height="1"&gt;</content><author><name>zahidnub445</name><uri>http://msdnbangladesh.net/members/zahidnub445/default.aspx</uri></author></entry><entry><title>A Journey to Silverlight 4 world</title><link rel="alternate" type="text/html" href="/blogs/zahid/archive/2010/07/20/a-journey-to-silverlight-4-world.aspx" /><id>/blogs/zahid/archive/2010/07/20/a-journey-to-silverlight-4-world.aspx</id><published>2010-07-19T22:27:51Z</published><updated>2010-07-19T22:27:51Z</updated><content type="html">&lt;p align="justify"&gt;I have been working on Silverlight since Silverlight 2 when there is now good designer tools&amp;#160; for developer. But now Silverlight 4 have become more matured and rich. To support silverlight application development faster Visual Studio 2010 introduce a Design View. Design view provides a visual design surface for building Silverlight controls and the layout of applications. It shows a rendering of the XAML currently in XAML view. If any changes make on the design surface, XAML view updates to reflect that changes.&lt;/p&gt;  &lt;p align="justify"&gt;I am going to share my experience in the journey of Silverlight with those who are willing to learn Silverlight but didn’t start yet. I will start from very basic so that absolute beginner can able to understand. It is a step-by-step article focus on some basic questions. Those who are already in the journey they will find some good resources which i have found after lots of Googling.&lt;/p&gt;  &lt;p align="justify"&gt;&lt;strong&gt;What is Silverlight?&lt;/strong&gt;&lt;/p&gt;  &lt;p align="justify"&gt;According to Silverlight Document “Microsoft Silverlight is a cross-browser, cross-platform implementation of the .NET Framework for building and delivering the next generation of media experiences and rich interactive applications (RIA) for the Web. Silverlight unifies the capabilities of the server, the Web, and the desktop, of managed code and dynamic languages, of declarative and traditional programming, and the power of Windows Presentation Foundation (WPF).”&lt;/p&gt;  &lt;p align="justify"&gt;&lt;strong&gt;What&amp;#39;s New in Silverlight 4?&lt;/strong&gt;&lt;/p&gt;  &lt;p align="justify"&gt;In spite of some disabilities Silverlight 4 brings so many new Features for Application Developers. I am not going to let you know about all those exciting features. &lt;/p&gt;  &lt;div align="justify"&gt;   &lt;table border="0" cellspacing="0" cellpadding="2" width="1019"&gt;&lt;tbody&gt;       &lt;tr&gt;         &lt;td valign="top" width="443"&gt;           &lt;ul&gt;             &lt;li&gt;Tooling &lt;/li&gt;              &lt;li&gt;Printing API &lt;/li&gt;              &lt;li&gt;Right-click event handling &lt;/li&gt;              &lt;li&gt;Webcam/microphone access &lt;/li&gt;              &lt;li&gt;Mouse wheel support &lt;/li&gt;              &lt;li&gt;RichTextArea Control &lt;/li&gt;              &lt;li&gt;ICommand support &lt;/li&gt;              &lt;li&gt;Clipboard API &lt;/li&gt;              &lt;li&gt;HTML Hosting with WebBrowser &lt;/li&gt;              &lt;li&gt;Elevated trust applications &lt;/li&gt;              &lt;li&gt;Local file access &lt;/li&gt;              &lt;li&gt;COM interop &lt;/li&gt;              &lt;li&gt;Notification (“toast”) API &lt;/li&gt;              &lt;li&gt;Network authentication &lt;/li&gt;              &lt;li&gt;Cross-domain Networking changes &lt;/li&gt;              &lt;li&gt;Keyboard access in full screen mode &lt;/li&gt;              &lt;li&gt;Text trimming&amp;#160; &lt;/li&gt;           &lt;/ul&gt;         &lt;/td&gt;          &lt;td valign="top" width="574"&gt;           &lt;ul&gt;             &lt;li&gt;ViewBox &lt;/li&gt;              &lt;li&gt;Right-to-left, BiDi and complex script &lt;/li&gt;              &lt;li&gt;Offline DRM &lt;/li&gt;              &lt;li&gt;H.264 protected content &lt;/li&gt;              &lt;li&gt;Silverlight as a drop target &lt;/li&gt;              &lt;li&gt;Data binding                &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; o IDataErrorInfo and Async Validation                 &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; o DependencyObject Binding                 &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; o StringFormat, TargetNullValue, FallbackValue &lt;/li&gt;              &lt;li&gt;Managed Extensibility Framework (MEF) &lt;/li&gt;              &lt;li&gt;DataGrid enhancements &lt;/li&gt;              &lt;li&gt;Fluid UI support in items controls &lt;/li&gt;              &lt;li&gt;Implicit theming &lt;/li&gt;              &lt;li&gt;Google Chrome support &lt;/li&gt;           &lt;/ul&gt;         &lt;/td&gt;       &lt;/tr&gt;     &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt;  &lt;p align="justify"&gt;You can find all the new features in &lt;a href="http://msdn.microsoft.com/en-us/library/cc838158(VS.95).aspx" target="_blank"&gt;MSDN&lt;/a&gt; or &lt;a href="http://www.silverlight.net/getstarted/silverlight-4/" target="_blank"&gt;Silverlight&lt;/a&gt; and &lt;a href="http://timheuer.com/blog/archive/2009/11/18/whats-new-in-silverlight-4-complete-guide-new-features.aspx"&gt;Silverlight 4 Beta – A guide to the new features&lt;/a&gt;&lt;/p&gt;  &lt;p align="justify"&gt;&lt;strong&gt;Silverlight Architecture?&lt;/strong&gt;&lt;/p&gt;  &lt;p align="justify"&gt;Silverlight platform consist of two major parts (Core presentation framework and .NET Framework for Silverlight) and an installer and update component.&lt;/p&gt;  &lt;p align="justify"&gt;In order to understand how Silverlight application works we need to take a close look at the silverlight Architecture.&lt;/p&gt;  &lt;p align="justify"&gt;&lt;a href="http://msdnbangladesh.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/zahid/IC302246_5F00_692F7B0F.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="IC302246" border="0" alt="IC302246" src="http://msdnbangladesh.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/zahid/IC302246_5F00_thumb_5F00_621FA2BD.png" width="212" height="244" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p align="justify"&gt;You will find more about the silverlight application’s Architecture form &lt;a href="http://msdn.microsoft.com/en-us/library/bb404713(v=VS.95).aspx" target="_blank"&gt;here&lt;/a&gt;&lt;/p&gt;  &lt;p align="justify"&gt;Prerequisites for Silverlight 4 application development&lt;/p&gt;  &lt;p align="justify"&gt;To begin with you will need to install Visual Studio 2010 or Visual Web Developer 2010 Express , and then install the Silverlight 4 Tools for Visual Studio 2010.( you will get Silverlight 3 in Visual Studio 2010 by default). You will get Silverlight 4 Tools for Visual Studio 2010 from &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=eff8a0da-0a4d-48e8-8366-6ddf2ecad801&amp;amp;displaylang=en%20" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p align="justify"&gt;When you install the Silverlight 4 Tools, the following components are installed. &lt;/p&gt;  &lt;p align="justify"&gt;· Silverlight 4 developer runtime    &lt;br /&gt;· Silverlight 4 SDK     &lt;br /&gt;· Updates to Visual Studio to support Silverlight 4 features     &lt;br /&gt;· &lt;a href="http://go.microsoft.com/fwlink/?LinkID=177512"&gt;WCF RIA Services&lt;/a&gt;&lt;/p&gt;  &lt;p align="justify"&gt;So if we are ready to develop our first application in Silverlight 4. &lt;/p&gt;  &lt;p align="justify"&gt;Open Visual Studio 2010 and Open a new project.    &lt;br /&gt;Open Visual Studio 2008 beta 2 and click &lt;i&gt;File &amp;gt; New &amp;gt; Project&lt;/i&gt;; then choose &lt;i&gt;Silverlight Project&lt;/i&gt;; enter the project name &amp;quot;&lt;i&gt;FirstSilverlightApp&lt;/i&gt;&amp;quot; and click OK :&lt;/p&gt;  &lt;p align="justify"&gt;&amp;#160;&lt;/p&gt;  &lt;p align="justify"&gt;&lt;a href="http://msdnbangladesh.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/zahid/clip_5F00_image002_5F00_579ECE9D.jpg"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="clip_image002" border="0" alt="clip_image002" src="http://msdnbangladesh.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/zahid/clip_5F00_image002_5F00_thumb_5F00_2E3760D2.jpg" width="244" height="150" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p align="justify"&gt;&amp;#160;&lt;/p&gt;  &lt;p align="justify"&gt;If we successfully installed the Silverlight 4 Tools for Visual Studio 2010, the option to target Silverlight 4 will appear. &lt;/p&gt;  &lt;p align="justify"&gt;&amp;#160;&lt;/p&gt;  &lt;p align="justify"&gt;&lt;a href="http://msdnbangladesh.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/zahid/clip_5F00_image0027_5F00_63ECA62C.jpg"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="clip_image002[7]" border="0" alt="clip_image002[7]" src="http://msdnbangladesh.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/zahid/clip_5F00_image0027_5F00_thumb_5F00_0FF97D51.jpg" width="244" height="109" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p align="justify"&gt;&amp;#160;&lt;/p&gt;  &lt;p align="justify"&gt;A new standard Silverlight project is created. From the next post we will start from our first silverlight application and gradually we will explore Silverlight 4.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msdnbangladesh.net/aggbug.aspx?PostID=156685" width="1" height="1"&gt;</content><author><name>zahidnub445</name><uri>http://msdnbangladesh.net/members/zahidnub445/default.aspx</uri></author></entry><entry><title>XBAP versus Silverlight application</title><link rel="alternate" type="text/html" href="/blogs/zahid/archive/2009/06/24/xbap-versus-silverlight-application.aspx" /><id>/blogs/zahid/archive/2009/06/24/xbap-versus-silverlight-application.aspx</id><published>2009-06-24T06:38:34Z</published><updated>2009-06-24T06:38:34Z</updated><content type="html">&lt;p align="justify"&gt;WPF browser application (XBAP) and Silverlight both use XAML (Extensible Application Markup Language, pronounced&amp;#160; zammel ) is a declarative XML-based language created by Microsoft). The XBAP application offer a way to implement rich browser-based application. On the other hand, Silverlight also holds the same promise. Thats why a lots of questions came into my mind and i try to find out the answer of those questions. I want to share it with everyone. &lt;/p&gt;  &lt;p align="justify"&gt;Silverlight 1.0 or 2.o was a subset of WPF where a lots of controls were missing and was very limited for scripting ( We couldn&amp;#39;t use C# ). You can&amp;#39;t use 3D in silverlight 2. But the last release of Silverlight 3 wondering me because a lots of new controls and 3D come into action. So you can do almost anything that can be done by WPF. If you want to learn more about Silverlight 3 application &lt;a href="http://silverlight.net/community/" target="_blank"&gt;click here!&lt;/a&gt; &lt;/p&gt;  &lt;p align="justify"&gt;The questions that came to my mind are : &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="justify"&gt;what are the difference between WPF browser application (XBAP) and silverlight ? &lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="justify"&gt;When I should use which of these technology ? &lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p align="justify"&gt;Developer today are becoming more and more conscious about the issues such as difference between xbap and silverlight and which technology we will use. This topic has given birth of vast controversy. I will try to explain these from my perspective.&lt;/p&gt;  &lt;p align="justify"&gt;XAML browser applications (XBAPs) combines the power of both Web applications and rich-client applications. XBAP can be published to a Web server like Web applications. Like rich-client applications, XBAPs can take advantage of the capabilities of WPF. Developing XBAP is also similar to rich-client development. XBAP application run inside the Internet Explorer and Mozilla Firefox in a separate sandbox to prevent applications from accessing resources on the local system. A restriction on XBAPs is that they need .NET framework 3.0 or higher to be installed on the client machine to run. &lt;/p&gt;  &lt;p align="justify"&gt;Silverlight is a runtime for browser-based Rich Internet Applications. Which is a subset of the animation, vector graphics, and video playback capabilities of Windows Presentation Foundation. So if you want your application to be available on the internet and not dependent on the .NET framework, Silverlight should be your choice. Silverlight is a cross platform, cross browser plug-in that allows you to run UIs defined in XAML inside the browser. &lt;/p&gt;  &lt;p align="justify"&gt;So WPF browser application (XBAP) is a good solution if you&amp;#39;re developing an internal corporate application( Intranet application) where you can dictate that everyone install the .Net Framework 3.0 or higher. For general purpose web sites open to the public, you can use Silverlight application otherwise it would be too high requirement for the users.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msdnbangladesh.net/aggbug.aspx?PostID=1342" width="1" height="1"&gt;</content><author><name>zahidnub445</name><uri>http://msdnbangladesh.net/members/zahidnub445/default.aspx</uri></author></entry><entry><title>Sending Email using WPF and C#</title><link rel="alternate" type="text/html" href="/blogs/zahid/archive/2009/03/23/sending-email-using-wpf-and-c.aspx" /><id>/blogs/zahid/archive/2009/03/23/sending-email-using-wpf-and-c.aspx</id><published>2009-03-22T18:59:09Z</published><updated>2009-03-22T18:59:09Z</updated><content type="html">&lt;p align="justify"&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/p&gt;  &lt;p align="justify"&gt;In this article you will learn how to send email from you WPF application using C#.Sending email from your WPF application is actually very simple.You can send email using SMTP Server that require authentication and SSL.You can use GMail&amp;#39;s SMTP server (smtp.gmail.com) to send Email.You will also need the SMTP Server&amp;#39;s port Number(For GMail: 587).Another thing, you are using GMail, so you need EnableSsl to be set to true, because GMail needs secure authentication to send email.I have made a Email Class (WPFEmailer.cs) that can use from both Windows Form and WPF application.I want to share it with all of you.&lt;/p&gt;  &lt;p align="justify"&gt;&lt;strong&gt;Using the Code&lt;/strong&gt;&lt;/p&gt;  &lt;p align="justify"&gt;If you go through the code, you will see that i have import the System.Net.Mail namespace.The System.Net.Mail namespace contains the SmtpClient and MailMessage Classes that we need in order to send the email.&lt;/p&gt;  &lt;p align="justify"&gt;&amp;#160;&lt;/p&gt;  &lt;div align="justify"&gt;   &lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;using &lt;/span&gt;System;
&lt;span style="color:blue;"&gt;using &lt;/span&gt;System.Collections.Generic;
&lt;span style="color:blue;"&gt;using &lt;/span&gt;System.Linq;
&lt;span style="color:blue;"&gt;using &lt;/span&gt;System.Text;
&lt;span style="color:blue;"&gt;using &lt;/span&gt;System.Net;
&lt;span style="color:blue;"&gt;using &lt;/span&gt;System.Net.Mail;
&lt;span style="color:blue;"&gt;using &lt;/span&gt;System.Threading;


&lt;span style="color:blue;"&gt;namespace &lt;/span&gt;EmailSendWPF
{
    &lt;span style="color:gray;"&gt;/// &amp;lt;summary&amp;gt;
    /// &lt;/span&gt;&lt;span style="color:green;"&gt;WPF Email Class
    &lt;/span&gt;&lt;span style="color:gray;"&gt;/// &amp;lt;/summary&amp;gt;
    &lt;/span&gt;&lt;span style="color:blue;"&gt;class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;WPFEmailer
    &lt;/span&gt;{
        &lt;span style="color:blue;"&gt;public string &lt;/span&gt;From = &lt;span style="color:blue;"&gt;string&lt;/span&gt;.Empty;
        &lt;span style="color:blue;"&gt;public string &lt;/span&gt;To = &lt;span style="color:blue;"&gt;string&lt;/span&gt;.Empty;
        &lt;span style="color:blue;"&gt;public string &lt;/span&gt;User = &lt;span style="color:blue;"&gt;string&lt;/span&gt;.Empty;
        &lt;span style="color:blue;"&gt;public string &lt;/span&gt;Password = &lt;span style="color:blue;"&gt;string&lt;/span&gt;.Empty;
        &lt;span style="color:blue;"&gt;public string &lt;/span&gt;Subject = &lt;span style="color:blue;"&gt;string&lt;/span&gt;.Empty;
        &lt;span style="color:blue;"&gt;public string &lt;/span&gt;Body = &lt;span style="color:blue;"&gt;string&lt;/span&gt;.Empty;
        &lt;span style="color:blue;"&gt;public string &lt;/span&gt;AttachmentPath = &lt;span style="color:blue;"&gt;string&lt;/span&gt;.Empty;
        &lt;span style="color:blue;"&gt;public string &lt;/span&gt;Host = &lt;span style="color:#a31515;"&gt;&amp;quot;127.0.0.1&amp;quot;&lt;/span&gt;;
        &lt;span style="color:blue;"&gt;public int &lt;/span&gt;Port = 25;
        &lt;span style="color:blue;"&gt;public string &lt;/span&gt;CC = &lt;span style="color:blue;"&gt;string&lt;/span&gt;.Empty;
        &lt;span style="color:blue;"&gt;public bool &lt;/span&gt;IsHtml = &lt;span style="color:blue;"&gt;false&lt;/span&gt;;
        &lt;span style="color:blue;"&gt;public int &lt;/span&gt;SendUsing = 0;&lt;span style="color:green;"&gt;//0 = Network, 1 = PickupDirectory, 2 = SpecifiedPickupDirectory
        &lt;/span&gt;&lt;span style="color:blue;"&gt;public bool &lt;/span&gt;UseSSL=&lt;span style="color:blue;"&gt;true&lt;/span&gt;;
        &lt;span style="color:blue;"&gt;public int &lt;/span&gt;AuthenticationMode=1;&lt;span style="color:green;"&gt;//0 = No authentication, 1 = Plain Text, 2 = NTLM authentication
        
        &lt;/span&gt;&lt;span style="color:blue;"&gt;public &lt;/span&gt;WPFEmailer()
        {
            
        }
       
        &lt;span style="color:blue;"&gt;public void &lt;/span&gt;SendEmail()
        {
            &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Thread&lt;/span&gt;(&lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;ThreadStart&lt;/span&gt;(SendMessage)).Start();
        }
        &lt;span style="color:gray;"&gt;/// &amp;lt;summary&amp;gt;
        /// &lt;/span&gt;&lt;span style="color:green;"&gt;Send Email Message method.
        &lt;/span&gt;&lt;span style="color:gray;"&gt;/// &amp;lt;/summary&amp;gt;
        &lt;/span&gt;&lt;span style="color:blue;"&gt;private void &lt;/span&gt;SendMessage()
        {
            &lt;span style="color:blue;"&gt;try
            &lt;/span&gt;{
                &lt;span style="color:#2b91af;"&gt;MailMessage &lt;/span&gt;oMessage = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;MailMessage&lt;/span&gt;();
                &lt;span style="color:#2b91af;"&gt;SmtpClient &lt;/span&gt;smtpClient = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;SmtpClient&lt;/span&gt;(Host);
            
                oMessage.From = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;MailAddress&lt;/span&gt;(From);
                oMessage.To.Add(To);
                oMessage.Subject = Subject;
                oMessage.IsBodyHtml = IsHtml; 
                oMessage.Body = Body;

                &lt;span style="color:blue;"&gt;if &lt;/span&gt;(CC != &lt;span style="color:blue;"&gt;string&lt;/span&gt;.Empty)                   
                    oMessage.CC.Add(CC);
                            
                &lt;span style="color:blue;"&gt;switch &lt;/span&gt;(SendUsing)
                { 
                    &lt;span style="color:blue;"&gt;case &lt;/span&gt;0:
                        smtpClient.DeliveryMethod = &lt;span style="color:#2b91af;"&gt;SmtpDeliveryMethod&lt;/span&gt;.Network;
                        &lt;span style="color:blue;"&gt;break&lt;/span&gt;;
                    &lt;span style="color:blue;"&gt;case &lt;/span&gt;1:
                        smtpClient.DeliveryMethod = &lt;span style="color:#2b91af;"&gt;SmtpDeliveryMethod&lt;/span&gt;.PickupDirectoryFromIis;
                        &lt;span style="color:blue;"&gt;break&lt;/span&gt;;
                    &lt;span style="color:blue;"&gt;case &lt;/span&gt;2:
                        smtpClient.DeliveryMethod = &lt;span style="color:#2b91af;"&gt;SmtpDeliveryMethod&lt;/span&gt;.SpecifiedPickupDirectory;
                        &lt;span style="color:blue;"&gt;break&lt;/span&gt;;
                    &lt;span style="color:blue;"&gt;default &lt;/span&gt;:
                        smtpClient.DeliveryMethod=&lt;span style="color:#2b91af;"&gt;SmtpDeliveryMethod&lt;/span&gt;.Network;
                        &lt;span style="color:blue;"&gt;break&lt;/span&gt;;
                
                }            
                &lt;span style="color:blue;"&gt;if&lt;/span&gt;(AuthenticationMode &amp;gt; 0)
                {
                    smtpClient.Credentials = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;NetworkCredential&lt;/span&gt;(User,Password);
                }                            
                
                smtpClient.Port = Port;
                smtpClient.EnableSsl = UseSSL;

                &lt;span style="color:green;"&gt;// Create and add the attachment
                &lt;/span&gt;&lt;span style="color:blue;"&gt;if&lt;/span&gt;(AttachmentPath!=&lt;span style="color:blue;"&gt;string&lt;/span&gt;.Empty)
                {                    
                    oMessage.Attachments.Add(&lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Attachment&lt;/span&gt;(AttachmentPath));
                }

                &lt;span style="color:blue;"&gt;try
                &lt;/span&gt;{
                    &lt;span style="color:green;"&gt;// Deliver the message    
                    &lt;/span&gt;smtpClient.Send(oMessage);                    
                    
                }
                
                &lt;span style="color:blue;"&gt;catch&lt;/span&gt;( &lt;span style="color:#2b91af;"&gt;Exception &lt;/span&gt;ex )
                {
                    ex.ToString();
                    
                }                
            }
            &lt;span style="color:blue;"&gt;catch&lt;/span&gt;(&lt;span style="color:#2b91af;"&gt;Exception &lt;/span&gt;ex)
            {
                ex.ToString();
            }
        }

    }
}&lt;/pre&gt;
&lt;/div&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p align="justify"&gt;From the above &lt;strong&gt;WPFEmailer.cs&lt;/strong&gt; you see that there are some property that is useful for email sending application.Using this class you can send Text or HTML email. You can attached file by specifying &lt;strong&gt;AttachmentPath&lt;/strong&gt; property as the path of the attached file that you want to send with your email. You have to specify all the property like User, Password, From, To , Host (SMTP Server Name), Port (Port Number), IsHtml and UseSSL as true or false.&lt;/p&gt;

&lt;p align="justify"&gt;You can use this class in your application to send email. You can use it in both WPF and Windows application. In this article i will show you how can you use it to send email from WPF application.&lt;/p&gt;

&lt;p align="justify"&gt;&amp;#160;&lt;/p&gt;

&lt;p align="justify"&gt;&lt;strong&gt;Example use&lt;/strong&gt;&lt;/p&gt;

&lt;p align="justify"&gt;I have use a WPF application to send email.The &lt;strong&gt;Windows Presentation Foundation&lt;/strong&gt; (or &lt;strong&gt;WPF&lt;/strong&gt;), formerly code-named &lt;strong&gt;Avalon&lt;/strong&gt;, is a graphical subsystem in&lt;strong&gt; .NET Framework 3.0&lt;/strong&gt;, which uses a markup language, known as &lt;strong&gt;XAML&lt;/strong&gt; for rich &lt;strong&gt;user interface&lt;/strong&gt; development.&lt;/p&gt;

&lt;p align="justify"&gt;&amp;#160;&lt;/p&gt;

&lt;p align="justify"&gt;&lt;a href="http://msdnbangladesh.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/zahid/WPFEmailer_5F00_582A2228.jpg"&gt;&lt;img title="WPFEmailer" style="border-right:0px;border-top:0px;display:inline;border-left:0px;border-bottom:0px;" height="244" alt="WPFEmailer" src="http://msdnbangladesh.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/zahid/WPFEmailer_5F00_thumb_5F00_5E2E9278.jpg" width="244" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p align="justify"&gt;&amp;#160;&lt;/p&gt;

&lt;p align="justify"&gt;The XAML code of the application is very simple but i want to share one thing with the &lt;strong&gt;beginner&lt;/strong&gt; of WPF is that the TextBox doesn&amp;#39;t have a password mode. Instead, there&amp;#39;s a special control for this: PasswordBox.Use PasswordBox control and set PasswordChar as &amp;#39;*&amp;#39;&lt;/p&gt;

&lt;p align="justify"&gt;&amp;#160;&lt;/p&gt;

&lt;div align="justify"&gt;
  &lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Window &lt;/span&gt;&lt;span style="color:red;"&gt;x&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:red;"&gt;Class&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;EmailSendWPF.Window1&amp;quot;
    &lt;/span&gt;&lt;span style="color:red;"&gt;xmlns&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot;
    &lt;/span&gt;&lt;span style="color:red;"&gt;xmlns&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:red;"&gt;x&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;
    &lt;/span&gt;&lt;span style="color:red;"&gt;Title&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;WPF Emailer&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Height&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;300&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Width&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;300&amp;quot;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Grid&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Grid.ColumnDefinitions&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;ColumnDefinition &lt;/span&gt;&lt;span style="color:red;"&gt;Width&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;122*&amp;quot; /&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;ColumnDefinition &lt;/span&gt;&lt;span style="color:red;"&gt;Width&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;156*&amp;quot; /&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Grid.ColumnDefinitions&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Grid.RowDefinitions&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;RowDefinition &lt;/span&gt;&lt;span style="color:red;"&gt;Height&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;227*&amp;quot; /&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;RowDefinition &lt;/span&gt;&lt;span style="color:red;"&gt;Height&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;35*&amp;quot; /&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Grid.RowDefinitions&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Button &lt;/span&gt;&lt;span style="color:red;"&gt;Name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;btnSendEmail&amp;quot;  &lt;/span&gt;&lt;span style="color:red;"&gt;Grid.Column&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;1&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Grid.Row&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;1&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Height&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;23&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;VerticalAlignment&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Top&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;HorizontalAlignment&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Left&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Width&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;74&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Click&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;btnSendEmail_Click&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Send Email&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Button&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;StackPanel &lt;/span&gt;&lt;span style="color:red;"&gt;Name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;stackPanel1&amp;quot; &amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Label &lt;/span&gt;&lt;span style="color:red;"&gt;Height&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;28&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;label1&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Width&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;auto&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;HorizontalAlignment&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Right&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Mail From&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Label&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Label &lt;/span&gt;&lt;span style="color:red;"&gt;Height&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;28&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;label2&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Width&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;auto&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;HorizontalAlignment&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Right&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Password&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Label&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Label &lt;/span&gt;&lt;span style="color:red;"&gt;Height&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;28&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;label3&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Width&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;auto&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;HorizontalAlignment&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Right&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Mail To&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Label&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Label &lt;/span&gt;&lt;span style="color:red;"&gt;Height&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;28&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;label4&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Width&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;auto&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;HorizontalAlignment&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Right&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;SMTP Server Name&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Label&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Label &lt;/span&gt;&lt;span style="color:red;"&gt;Height&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;28&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;label5&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Width&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;auto&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;HorizontalAlignment&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Right&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;SMTP Port Number&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Label&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Label &lt;/span&gt;&lt;span style="color:red;"&gt;Height&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;28&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;label6&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Width&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;auto&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;HorizontalAlignment&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Right&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Subject&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Label&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Label &lt;/span&gt;&lt;span style="color:red;"&gt;Height&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;28&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;label7&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Width&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;auto&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;HorizontalAlignment&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Right&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Body&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Label&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;StackPanel&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;StackPanel &lt;/span&gt;&lt;span style="color:red;"&gt;Grid.Column&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;1&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;stackPanel2&amp;quot;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;TextBox &lt;/span&gt;&lt;span style="color:red;"&gt;Height&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;20&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;txtUserName&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Width&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;auto&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Margin&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;0,6,6,3&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;ToolTip&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Example: yourmail@gmail.com&amp;quot; /&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;PasswordBox &lt;/span&gt;&lt;span style="color:red;"&gt;Height&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;20&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;txtPassword&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Width&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;auto&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Margin&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;0,3,6,3&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;PasswordChar&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;*&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;ToolTip&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Your Password.&amp;quot; /&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;TextBox &lt;/span&gt;&lt;span style="color:red;"&gt;Height&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;20&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;txtTo&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Width&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;auto&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Margin&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;0,6,6,3&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;ToolTip&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Example: SendTo@yahoo.com&amp;quot; /&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;TextBox &lt;/span&gt;&lt;span style="color:red;"&gt;Height&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;20&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;txtSMTPServerName&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Width&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;auto&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Margin&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;0,5,6,3&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;ToolTip&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Example: smtp.gmail.com&amp;quot; /&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;TextBox &lt;/span&gt;&lt;span style="color:red;"&gt;Height&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;20&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;txtSMTPPortNumber&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Width&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;auto&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Margin&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;0,3,6,3&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;ToolTip&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Example: For gmail is 587&amp;quot; /&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;TextBox &lt;/span&gt;&lt;span style="color:red;"&gt;Height&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;20&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;txtSubject&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Width&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;auto&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Margin&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;0,5,6,3&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;ToolTip&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Email Subject!&amp;quot; /&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;TextBox &lt;/span&gt;&lt;span style="color:red;"&gt;Height&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;53&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;txtBody&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Width&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;auto&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Margin&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;0,3,6,6&amp;quot;
                     &lt;/span&gt;&lt;span style="color:red;"&gt;TextWrapping&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Wrap&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;ToolTip&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Eamil Body Here!&amp;quot; /&amp;gt;
            
        &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;StackPanel&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Button &lt;/span&gt;&lt;span style="color:red;"&gt;Grid.Column&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;1&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Margin&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;78,0,0,0&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;btnCancel&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Grid.Row&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;1&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;HorizontalAlignment&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Left&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Width&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;74&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Height&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;23&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;VerticalAlignment&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Top&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Click&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;btnCancel_Click&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Cancel&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Button&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Grid&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Window&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p align="justify"&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p align="justify"&gt;Use the following code to send email using &lt;strong&gt;WPFEmailer.cs&lt;/strong&gt; Class.&lt;/p&gt;

&lt;p align="justify"&gt;&amp;#160;&lt;/p&gt;

&lt;div align="justify"&gt;
  &lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;private void &lt;/span&gt;btnSendEmail_Click(&lt;span style="color:blue;"&gt;object &lt;/span&gt;sender, &lt;span style="color:#2b91af;"&gt;RoutedEventArgs &lt;/span&gt;e)
        {
            &lt;span style="color:#2b91af;"&gt;WPFEmailer &lt;/span&gt;wpfEmailer = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;WPFEmailer&lt;/span&gt;();
            wpfEmailer.User = txtUserName.Text;
            wpfEmailer.Password = txtPassword.Password;
            wpfEmailer.From = txtUserName.Text;
            wpfEmailer.To = txtTo.Text;
            wpfEmailer.Host = txtSMTPServerName.Text;
            wpfEmailer.Port = &lt;span style="color:#2b91af;"&gt;Convert&lt;/span&gt;.ToInt32(txtSMTPPortNumber.Text);
            wpfEmailer.Subject = txtSubject.Text;
            wpfEmailer.Body = txtBody.Text;
            &lt;span style="color:blue;"&gt;try
            &lt;/span&gt;{
                wpfEmailer.SendEmail();
                &lt;span style="color:#2b91af;"&gt;MessageBox&lt;/span&gt;.Show(&lt;span style="color:#a31515;"&gt;&amp;quot;Message send successfully.&amp;quot;&lt;/span&gt;);
            }
            &lt;span style="color:blue;"&gt;catch &lt;/span&gt;(&lt;span style="color:#2b91af;"&gt;Exception &lt;/span&gt;ex)
            {
                &lt;span style="color:#2b91af;"&gt;MessageBox&lt;/span&gt;.Show(&lt;span style="color:#a31515;"&gt;&amp;quot;Error:&amp;quot;&lt;/span&gt;+ex.ToString());
            }
        }&lt;/pre&gt;
&lt;/div&gt;

&lt;div align="justify"&gt;
  &lt;pre class="code"&gt;You can do many things using this WPFEmailer.cs Class.&lt;/pre&gt;
&lt;/div&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p align="justify"&gt;If you want to send HTML page as Email then just set the IsHtml property of the WPFEmailer.cs class as True. If you want to attach a file with the email then just attached the path of the file to the AttachmentPath property. That&amp;#39;s all.&lt;/p&gt;

&lt;p align="justify"&gt;Isn&amp;#39;t it easy? So enjoy sending email. If you have any question just send me email or post your comments. Thank you.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msdnbangladesh.net/aggbug.aspx?PostID=352" width="1" height="1"&gt;</content><author><name>zahidnub445</name><uri>http://msdnbangladesh.net/members/zahidnub445/default.aspx</uri></author></entry><entry><title>Getting object’s information on the fly</title><link rel="alternate" type="text/html" href="/blogs/zahid/archive/2009/03/20/getting-object-s-information-on-the-fly.aspx" /><id>/blogs/zahid/archive/2009/03/20/getting-object-s-information-on-the-fly.aspx</id><published>2009-03-19T22:17:53Z</published><updated>2009-03-19T22:17:53Z</updated><content type="html">&lt;p align="justify"&gt;Do you ever try to find out information about an object at run time? Though all of us working with object all the day but I think few of us try this. It is very useful when you want to interrogate types in the system as well as to create code on the fly.&lt;/p&gt;  &lt;p align="justify"&gt;.NET Framework provides a feature called &lt;strong&gt;Reflection&lt;/strong&gt; which enables us to get information about object, fields, properties, or events contains at runtime. &lt;/p&gt;  &lt;p align="justify"&gt;&lt;strong&gt;Wikipedia says that&lt;/strong&gt; &amp;quot;In computer science, reflection is the process by which a computer program can observe and modify its own structure and behavior&amp;quot;.&lt;/p&gt;  &lt;p align="justify"&gt;System.Reflection namespace contains all the Reflection related classes. These classes are used to get information from any of the class under .NET framework.The Type class is the root of all reflection operations. &lt;/p&gt;  &lt;p align="justify"&gt;&lt;strong&gt;We can get Type objects in a number of ways:&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="justify"&gt;When working with assembly, we can get all the Types form all the modules of the assembly by calling the GetTypes method.&lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;blockquote&gt;   &lt;div align="justify"&gt;     &lt;pre class="code"&gt;&lt;span style="color:#2b91af;"&gt;Assembly &lt;/span&gt;assembly = &lt;span style="color:#2b91af;"&gt;Assembly&lt;/span&gt;.GetExecutingAssembly();
&lt;span style="color:green;"&gt;// Get all the types in the Assembly
&lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Type&lt;/span&gt;[] assemblyType = assembly.GetType();&lt;/pre&gt;
  &lt;/div&gt;
  &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;div align="justify"&gt;When working with module object, we can get all the Types associated with the modules.&lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;div align="justify"&gt;
    &lt;pre class="code"&gt;&lt;span style="color:#2b91af;"&gt;Module&lt;/span&gt;[] modules = assembly.GetModules();&lt;/pre&gt;
  &lt;/div&gt;
  &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;div align="justify"&gt;We can get the type of an object by calling the GetType method or using &lt;span style="color:blue;"&gt;typeof &lt;/span&gt;keyword. &lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;div align="justify"&gt;
    &lt;pre class="code"&gt;&lt;span style="color:#2b91af;"&gt;Object &lt;/span&gt;obj = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Object&lt;/span&gt;();
&lt;span style="color:green;"&gt;// Get the type of an object
&lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Type &lt;/span&gt;objectType = obj.GetType();&lt;/pre&gt;
  &lt;/div&gt;
  &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p align="justify"&gt;or&lt;/p&gt;

  &lt;div align="justify"&gt;
    &lt;pre class="code"&gt;&lt;span style="color:#2b91af;"&gt;Type &lt;/span&gt;objectType = &lt;span style="color:blue;"&gt;typeof&lt;/span&gt;(obj);&lt;/pre&gt;
  &lt;/div&gt;
  &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/blockquote&gt;

&lt;p align="justify"&gt;&lt;strong&gt;The following member methods of Type follow the same pattern:&lt;/strong&gt;&amp;#160;&lt;/p&gt;

&lt;div align="justify"&gt;
  &lt;table cellspacing="0" cellpadding="2" width="400" border="1"&gt;&lt;tbody&gt;
      &lt;tr&gt;
        &lt;td valign="top" width="199"&gt;&lt;strong&gt;Type of Object Returned&lt;/strong&gt;&lt;/td&gt;

        &lt;td valign="top" width="199"&gt;&lt;strong&gt;Methods&lt;/strong&gt;&lt;/td&gt;
      &lt;/tr&gt;

      &lt;tr&gt;
        &lt;td valign="top" width="199"&gt;ConstructorInfo&lt;/td&gt;

        &lt;td valign="top" width="199"&gt;GetConostructor(), GetConostructors()&lt;/td&gt;
      &lt;/tr&gt;

      &lt;tr&gt;
        &lt;td valign="top" width="199"&gt;EventInfo&lt;/td&gt;

        &lt;td valign="top" width="199"&gt;GetEvent(), GetEvents()&lt;/td&gt;
      &lt;/tr&gt;

      &lt;tr&gt;
        &lt;td valign="top" width="199"&gt;FieldInfo&lt;/td&gt;

        &lt;td valign="top" width="199"&gt;GetField(),GetFields()&lt;/td&gt;
      &lt;/tr&gt;

      &lt;tr&gt;
        &lt;td valign="top" width="199"&gt;InterfaceInfo&lt;/td&gt;

        &lt;td valign="top" width="199"&gt;GetInterface(),GetInterfaces()&lt;/td&gt;
      &lt;/tr&gt;

      &lt;tr&gt;
        &lt;td valign="top" width="199"&gt;MemberInfo&lt;/td&gt;

        &lt;td valign="top" width="199"&gt;GetMember(),GetMembers()&lt;/td&gt;
      &lt;/tr&gt;

      &lt;tr&gt;
        &lt;td valign="top" width="199"&gt;MethodInfo&lt;/td&gt;

        &lt;td valign="top" width="199"&gt;GetMethod();GetMembers()&lt;/td&gt;
      &lt;/tr&gt;

      &lt;tr&gt;
        &lt;td valign="top" width="199"&gt;PropertyInfo&lt;/td&gt;

        &lt;td valign="top" width="200"&gt;GetProperty(),GetProperty()&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;

&lt;div align="justify"&gt;&amp;#160;&lt;/div&gt;

&lt;p align="justify"&gt;Let see an example where we will create a class, make an object of that class and then we will find out the information about that object.&lt;/p&gt;

&lt;p align="justify"&gt;&lt;strong&gt;Here is the Customer Class:&lt;/strong&gt;&lt;/p&gt;

&lt;div align="justify"&gt;
  &lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Customer
    &lt;/span&gt;{
        &lt;span style="color:green;"&gt;//Public fields
        &lt;/span&gt;&lt;span style="color:blue;"&gt;public int &lt;/span&gt;ID;
        &lt;span style="color:blue;"&gt;public string &lt;/span&gt;Name;
        &lt;span style="color:blue;"&gt;public &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Dealer &lt;/span&gt;oDealer;
        
        &lt;span style="color:green;"&gt;//Public property
        &lt;/span&gt;&lt;span style="color:blue;"&gt;public int &lt;/span&gt;IDProperty { &lt;span style="color:blue;"&gt;get&lt;/span&gt;; &lt;span style="color:blue;"&gt;set&lt;/span&gt;; }
        &lt;span style="color:blue;"&gt;public string &lt;/span&gt;StringProperty { &lt;span style="color:blue;"&gt;get&lt;/span&gt;; &lt;span style="color:blue;"&gt;set&lt;/span&gt;; }
        &lt;span style="color:blue;"&gt;public &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Dealer &lt;/span&gt;ObjectProperty { &lt;span style="color:blue;"&gt;get&lt;/span&gt;; &lt;span style="color:blue;"&gt;set&lt;/span&gt;; }

        &lt;span style="color:green;"&gt;//Public Method
        &lt;/span&gt;&lt;span style="color:blue;"&gt;public void &lt;/span&gt;insertCustomer()
        { }
        &lt;span style="color:blue;"&gt;public void &lt;/span&gt;deleteCustomer()
        { }
        &lt;span style="color:green;"&gt;////public events
        &lt;/span&gt;&lt;span style="color:blue;"&gt;public event &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;EventHandler &lt;/span&gt;MyEvent1;
        &lt;span style="color:blue;"&gt;public event &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;EventHandler &lt;/span&gt;MyEvent2;

    }&lt;/pre&gt;

  &lt;pre class="code"&gt;&amp;#160;&lt;/pre&gt;
&lt;/div&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p align="justify"&gt;&lt;strong&gt;Here is an object of Customer class:&lt;/strong&gt;&lt;/p&gt;

&lt;p align="justify"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Customer &lt;/span&gt;oCustomer =&lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Customer&lt;/span&gt;(); 

  &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; oCustomer.ID = 1002; 

  &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; oCustomer.Name = &lt;span style="color:#a31515;"&gt;&amp;quot;Zahid&amp;quot;&lt;/span&gt;; 

  &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; oCustomer.oDealer = oDelaer; &lt;/p&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;div align="justify"&gt;
  &lt;pre class="code"&gt;&lt;span style="color:#2b91af;"&gt;      Dealer &lt;/span&gt;oDelaer = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Dealer&lt;/span&gt;();
      oDelaer.ID = 1001;
      oDelaer.Name = &lt;span style="color:#a31515;"&gt;&amp;quot;Microsoft&amp;quot;&lt;/span&gt;;&lt;/pre&gt;

  &lt;pre class="code"&gt;&amp;#160;&lt;/pre&gt;
&lt;/div&gt;

&lt;p align="justify"&gt;Now we can find out the information of Customer by using Type Class. I write a class Reflection.cs. Using this class we can get information about Fields, Properties, Methods, Events etc of any class.&lt;/p&gt;

&lt;p align="justify"&gt;&lt;strong&gt;Here is the Reflection.cs:&lt;/strong&gt;&lt;/p&gt;

&lt;div align="justify"&gt;
  &lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Reflection
   &lt;/span&gt;{

       &lt;span style="color:blue;"&gt;public void &lt;/span&gt;getObjectInformation(&lt;span style="color:#2b91af;"&gt;Object &lt;/span&gt;obj)
       {
           &lt;span style="color:green;"&gt;//Get the Type 
           &lt;/span&gt;System.&lt;span style="color:#2b91af;"&gt;Type &lt;/span&gt;oType = obj.GetType();
           &lt;span style="color:blue;"&gt;string &lt;/span&gt;objectName = oType.Name;

           &lt;span style="color:green;"&gt;//info in the string of information about the object obj
           &lt;/span&gt;&lt;span style="color:blue;"&gt;string &lt;/span&gt;info = &lt;span style="color:#a31515;"&gt;&amp;quot;Class Name:&amp;quot; &lt;/span&gt;+ objectName + &lt;span style="color:#2b91af;"&gt;Environment&lt;/span&gt;.NewLine;

           &lt;span style="color:green;"&gt;//Get all the Fields information of the object
           &lt;/span&gt;System.Reflection.&lt;span style="color:#2b91af;"&gt;FieldInfo&lt;/span&gt;[] oFields = oType.GetFields();
           &lt;span style="color:blue;"&gt;foreach &lt;/span&gt;(System.Reflection.&lt;span style="color:#2b91af;"&gt;FieldInfo &lt;/span&gt;oField &lt;span style="color:blue;"&gt;in &lt;/span&gt;oFields)
           {
               info +=oField.Name + &lt;span style="color:#a31515;"&gt;&amp;quot; (&amp;quot;&lt;/span&gt;+oField.FieldType + &lt;span style="color:#a31515;"&gt;&amp;quot;):&amp;quot; &lt;/span&gt;+ oField.GetValue(obj) + &lt;span style="color:#2b91af;"&gt;Environment&lt;/span&gt;.NewLine;
           }

           &lt;span style="color:green;"&gt;//Get all the Property name of the object
           &lt;/span&gt;System.Reflection.&lt;span style="color:#2b91af;"&gt;PropertyInfo&lt;/span&gt;[] oPropertys = oType.GetProperties();
           &lt;span style="color:blue;"&gt;foreach &lt;/span&gt;(System.Reflection.&lt;span style="color:#2b91af;"&gt;MemberInfo &lt;/span&gt;oProperty &lt;span style="color:blue;"&gt;in &lt;/span&gt;oPropertys)
           {
               info +=&lt;span style="color:#a31515;"&gt;&amp;quot;Property Name:&amp;quot;&lt;/span&gt;+ oProperty.Name + &lt;span style="color:#2b91af;"&gt;Environment&lt;/span&gt;.NewLine;
           }
           
           &lt;span style="color:green;"&gt;//Get all the Events of the object
           &lt;/span&gt;System.Reflection.&lt;span style="color:#2b91af;"&gt;EventInfo&lt;/span&gt;[] oEvents = oType.GetEvents();
           &lt;span style="color:blue;"&gt;foreach &lt;/span&gt;(System.Reflection.&lt;span style="color:#2b91af;"&gt;EventInfo &lt;/span&gt;oEvent &lt;span style="color:blue;"&gt;in &lt;/span&gt;oEvents)
           {
               info += &lt;span style="color:#a31515;"&gt;&amp;quot;Event Name:&amp;quot; &lt;/span&gt;+ oEvent.Name + &lt;span style="color:#2b91af;"&gt;Environment&lt;/span&gt;.NewLine;
           }

           &lt;span style="color:green;"&gt;//Get all the Methods of the object
           &lt;/span&gt;System.Reflection.&lt;span style="color:#2b91af;"&gt;MethodInfo&lt;/span&gt;[] oMethods = oType.GetMethods();
           &lt;span style="color:blue;"&gt;foreach &lt;/span&gt;(System.Reflection.&lt;span style="color:#2b91af;"&gt;MethodInfo &lt;/span&gt;oMethod &lt;span style="color:blue;"&gt;in &lt;/span&gt;oMethods)
           {
               info += &lt;span style="color:#a31515;"&gt;&amp;quot;Method Name:&amp;quot; &lt;/span&gt;+ oMethod.Name + &lt;span style="color:#2b91af;"&gt;Environment&lt;/span&gt;.NewLine;
           }  
           &lt;span style="color:#2b91af;"&gt;MessageBox&lt;/span&gt;.Show(info);
       }        
   }&lt;/pre&gt;
&lt;/div&gt;

&lt;p align="justify"&gt;Isn’t it very easy but believe it Reflection is very powerful by using it you can dynamic generate code. I will show you how we can generate dynamic code using Reflection in next article.&lt;/p&gt;

&lt;p align="justify"&gt;I hope this article will help them who want to get information about objects at runtime. If anything didn&amp;#39;t make sense, or you&amp;#39;ve got other questions, just leave them in the comments.&lt;/p&gt;

&lt;p align="justify"&gt;&amp;#160;&lt;/p&gt;

&lt;p align="justify"&gt;&lt;strong&gt;Reference:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;div align="justify"&gt;&lt;a title="http://www.switchonthecode.com/tutorials/csharp-tutorial-using-reflection-to-get-object-information" href="http://www.switchonthecode.com/tutorials/csharp-tutorial-using-reflection-to-get-object-information"&gt;http://www.switchonthecode.com/tutorials/csharp-tutorial-using-reflection-to-get-object-information&lt;/a&gt;&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;&lt;a title="http://msdn.microsoft.com/en-us/library/system.reflection.aspx" href="http://msdn.microsoft.com/en-us/library/system.reflection.aspx"&gt;http://msdn.microsoft.com/en-us/library/system.reflection.aspx&lt;/a&gt;&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;Robinson, Nagel, Watson, Glaynn, Skinner, Evjen ,&lt;em&gt;&lt;strong&gt;Professional C#,4th Edithon&lt;/strong&gt;&lt;/em&gt;&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;&lt;em&gt;&lt;strong&gt;Microsft .NET Framework 2.0, Training kit&lt;/strong&gt;&lt;/em&gt;.&lt;/div&gt;
  &lt;/li&gt;
&lt;/ol&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msdnbangladesh.net/aggbug.aspx?PostID=345" width="1" height="1"&gt;</content><author><name>zahidnub445</name><uri>http://msdnbangladesh.net/members/zahidnub445/default.aspx</uri></author></entry></feed>
