<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>WPF/Silverlight Insiders &#187; Tutorials</title>
	<atom:link href="http://wsinsiders.com/category/silverlight-tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://wsinsiders.com</link>
	<description>Tutorials By Community, For Community</description>
	<lastBuildDate>Tue, 02 Feb 2010 01:47:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Silverlight Tutorials: Silverlight Basic &#8211; SpinningCube</title>
		<link>http://wsinsiders.com/2010/01/30/silverlight-tutorials-silverlight-basic-spinningcube/</link>
		<comments>http://wsinsiders.com/2010/01/30/silverlight-tutorials-silverlight-basic-spinningcube/#comments</comments>
		<pubDate>Sat, 30 Jan 2010 17:47:37 +0000</pubDate>
		<dc:creator>Michael Sync</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://wsinsiders.com/?p=286</guid>
		<description><![CDATA[This article is written by Einar Ingebrigtsen (Silverlight MVP). It is a part of &#8220;Silverlight Basic&#8221;, the third chapter of &#8220;Silverlight Tutorials for Beginners.&#8221; Download : SpinningCube.zip (12.9 KB) Silverlight represents a subset of WPF and it&#8217;s features, one of the features that aren&#8217;t part of the subset is 3D. Silverlight 3 introduces the ability [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>This article is written by <a href="http://www.ingebrigtsen.info/">Einar Ingebrigtsen (Silverlight MVP)</a>. It is a part of &#8220;Silverlight Basic&#8221;, the third chapter of &#8220;<strong><a href="http://wsinsiders.com/2010/01/29/silverlight-tutorials-for-beginners/">Silverlight Tutorials for Beginners</a></strong>.&#8221;</p></blockquote>
<p><strong>Download</strong> : <a href="http://wsinsiders.com/wp-content/uploads/SpinningCube.zip">SpinningCube.zip (12.9 KB)</a></p>
<p>Silverlight represents a subset of WPF and it&#8217;s features, one of the features that aren&#8217;t part of the subset is 3D. Silverlight 3 introduces the ability to project any UIElement in 3D by rotating them around the X,Y and Z axises. But geometries that consist on anything else but planes, typically triangles would not perform well using the PlaneProjection. Silverlight has primitives that can be used instead, such as Polygon. The Polygon can have N number of sides, at least 3, which is perfect for representing 3D models.</p>
<p>This tutorial is very basic and does not involve any heavy geometry math. If you want to do more advanced geometry stuff with cameras, texturemapping, lighting and such, Balder could be place to look. Balder is a full 3D engine I started writing back in early 2007 and is opensource, you can find it <a href="http://balder.codeplex.com/">here</a>.</p>
<h4>Getting started</h4>
<p>First thing you need to do is to create yourself a Silverlight project and leave all the defaults in.</p>
<h4>Rendering container</h4>
<p>This sample needs a container to add polygons to. When you first created the project a MainPage.xaml file was added to the project, opening it you&#8217;ll see there is a <Grid x:Name="LayoutRoot"> tag at the top. Lets give it a size and a background color:</p>
<p><img src="http://wsinsiders.com/wp-content/uploads/2010/01/1.-Silverlight-3D-Article-300x30.png" alt="" title="1. Silverlight 3D Article" width="300" height="30" /></p>
<p>Now we have a container that we can add polygons to that has a dimension of 640 by 480 pixels and the background is black.</p>
<h4>The rendering loop</h4>
<p>The first thing we will be needing is a timer that gets called on a regular basis for handling all the calculations and generation of polygons that will be visible on the display. It is very important that this timer is running in the same thread context as the main Silverlight thread. Manipulation of the visual tree is not allowed from other threads. Silverlight has something called the DispatcherTimer that we can use for this. The DispatcherTimer can run with the same framerate as the plugin has been specified to run with, default being 60 frames per second.</p>
<p>In the MainPage.xaml.cs file in your project, we need to add the following code in the constructor, right beneath the InitializeComponent() method call:</p>
<p><img src="http://wsinsiders.com/wp-content/uploads/2010/01/2.-Silverlight-3D-Article.png" alt="" title="2. Silverlight 3D Article" width="365" height="126" class="alignnone size-full wp-image-288" /></p>
<p>In the Tick event we are specifying a method called Render, which will be a method you have to add in the same class that will be called everytime rendering will occur:</p>
<p><img src="http://wsinsiders.com/wp-content/uploads/2010/01/3.-Silverlight-3D-Article.png" alt="" title="3. Silverlight 3D Article" width="341" height="55" class="alignnone size-full wp-image-289" /></p>
<h4>A cube</h4>
<p>To define our cube we need points in 3D space, these are called Vertices (one vertex, several vertices). We need to add a simple class to represent a vertex. The class represents the original vertex before we have done any calculations on it and also contains the finished calculated vertex ready to be used on our 2D screen.</p>
<p><img src="http://wsinsiders.com/wp-content/uploads/2010/01/4.-Silverlight-3D-Article.png" alt="" title="4. Silverlight 3D Article" width="376" height="104" class="alignnone size-full wp-image-290" /></p>
<p>As you can see, the vertex contains an X,Y and Z representing the coordinate in 3D space. In addition it contains the rotated version and the translated<br />
(2D) version. Now that we have the definition of a vertex, we need the definition of a triangle that hooks  itself on 3 vertices, we call these Faces. A face<br />
contains 3 integers representing an index into the array of vertices for the object we are rotating. Add a class called Face and make it look like this:</p>
<p><img src="http://wsinsiders.com/wp-content/uploads/2010/01/5.-Silverlight-3D-Article.png" alt="" title="5. Silverlight 3D Article" width="341" height="67" class="alignnone size-full wp-image-291" /></p>
<p>Next, we need the actual cube and methods for rendering itself. We create a class called Cube. In the Cube class we need to define the vertices that defines the cube. Add the following at the top of the class:</p>
<p><img src="http://wsinsiders.com/wp-content/uploads/2010/01/6.-Silverlight-3D-Article.png" alt="" title="6. Silverlight 3D Article" width="561" height="195" class="alignnone size-full wp-image-292" /></p>
<p>The purpose the constants at the top is to be able to change the size of the cube with ease.<br />
And we need an array of faces that hooks up to these vertices :</p>
<p><img src="http://wsinsiders.com/wp-content/uploads/2010/01/7.-Silverlight-3D-Article.png" alt="" title="7. Silverlight 3D Article" width="561" height="195" class="alignnone size-full wp-image-293" /></p>
<p>Next we need to actually render the cube. The rendering is divided into two processes, one for calculating all the vertices and one for generating the polygons. First we need to define a method for calculating the vertices:</p>
<p><img src="http://wsinsiders.com/wp-content/uploads/2010/01/8.-Silverlight-3D-Article.png" alt="" title="8. Silverlight 3D Article" width="561" height="307" class="alignnone size-full wp-image-294" /></p>
<p>Note that the method takes the rotation around the 3 axises in as parameters, and also something called xoffset and yoffset. </p>
<p>The offsets are used for centering the finished result, which will be shown later in the render method. Now we need a method for generating the polygons:</p>
<p><img src="http://wsinsiders.com/wp-content/uploads/2010/01/9.-Silverlight-3D-Article.png" alt="" title="9. Silverlight 3D Article" width="561" height="707" class="alignnone size-full wp-image-295" /></p>
<p>We now have all the methods we need to finish the rendering. In the Cube class, we expose a public method to tie it all together:</p>
<p><img src="http://wsinsiders.com/wp-content/uploads/2010/01/10.-Silverlight-3D-Article.png" alt="" title="10. Silverlight 3D Article" width="561" height="100" class="alignnone size-full wp-image-296" /></p>
<p>The method takes a panel as the container in which it will render all the polygons to and the rotation around the 3 axises.</p>
<p>The xoffset and yoffset is calculated by taking the containers width and height and divided by 2, which is the center of the container.</p>
<p>All we need now is to go back to our MainPage.xaml.cs file and create our cube and call the rendering method.</p>
<p>Add a private field holding the Cube instance, like this:</p>
<p><img src="http://wsinsiders.com/wp-content/uploads/2010/01/11.-Silverlight-3D-Article.png" alt="" title="11. Silverlight 3D Article" width="221" height="39" class="alignnone size-full wp-image-297" /></p>
<p>In the constructor we can now create the cube:</p>
<p><img src="http://wsinsiders.com/wp-content/uploads/2010/01/12.-Silverlight-3D-Article.png" alt="" title="12. Silverlight 3D Article" width="173" height="33" class="alignnone size-full wp-image-298" /></p>
<p>Then we define some variables that we can manipulate every time we render, these will be used for rotating the cube. In the MainPage class, add the following fields:</p>
<p><img src="http://wsinsiders.com/wp-content/uploads/2010/01/13.-Silverlight-3D-Article.png" alt="" title="13. Silverlight 3D Article" width="214" height="60" class="alignnone size-full wp-image-299" /></p>
<p>Now, we can add a body to the Render method:</p>
<p><img src="http://wsinsiders.com/wp-content/uploads/2010/01/14.-Silverlight-3D-Article.png" alt="" title="14. Silverlight 3D Article" width="437" height="122" class="alignnone size-full wp-image-300" /></p>
<p>That should be just about everything we need to get a spinning cube on the screen.<br />
The result should be something like this:</p>
<p><img src="http://wsinsiders.com/wp-content/uploads/2010/01/15.-Silverlight-3D-Article.png" alt="" title="15. Silverlight 3D Article" width="561" height="444" class="alignnone size-full wp-image-301" /></p>
<h4>Conclusion</h4>
<p>Silverlight has come a long way since its initial first release in 2007, but still real 3D is missing. In Silverlight 3 there has been done some work by Microsoft on the subject with the introduction of plane projection. For a simple cube like in this tutorial, one would be better off using that technique. But, if you want to represent more advanced geometries, the technique in this tutorial is better. There are some limitations though. Due to the way Silverlight works internally with the main rendering engine and the CLR being separated completely, there are speed limitations to how many polygons it is possible to render. So really complex geometries is something that would not perform well. Another issue is texturemapping. Silverlight does not give you any ability to represent the U,V coordinates within the texture for every point in a polygon. It is possible though to get this working by manipulating the matrix of the imagebrush specified, but again, performance will be impacted. In the <a href="http://balder.codeplex.com/">Balder</a> engine, we have overcome these limitations by creating our own drawing routines, not using any Silverlight primitives at all. Since the CLR is quite speedy, this enables us to draw quite complex objects.</p>
]]></content:encoded>
			<wfw:commentRss>http://wsinsiders.com/2010/01/30/silverlight-tutorials-silverlight-basic-spinningcube/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Silverlight Tutorials: Data Binding</title>
		<link>http://wsinsiders.com/2010/01/30/silverlight-tutorials-data-binding/</link>
		<comments>http://wsinsiders.com/2010/01/30/silverlight-tutorials-data-binding/#comments</comments>
		<pubDate>Sat, 30 Jan 2010 17:27:55 +0000</pubDate>
		<dc:creator>Michael Sync</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://wsinsiders.com/?p=284</guid>
		<description><![CDATA[This article is written by Emil Stoychev (Silverlight MVP).This is the fourth chapter of Silverlight Tutorials for Beginners series. Data Binding is simple, yet powerful way to connect (bind) your business model and user interface (UI). When the data in your business model changes the UI reflects changes automatically and vice versa (when a user [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>This article is written by <a href="http://emil.silverlightshow.net/">Emil Stoychev (Silverlight MVP)</a>.This is the fourth chapter of <strong><a href="http://wsinsiders.com/2010/01/29/silverlight-tutorials-for-beginners/">Silverlight Tutorials for Beginners</a></strong> series.</p></blockquote>
<p>Data Binding is simple, yet powerful way to connect (bind) your business model and user interface (UI). When the data in your business model changes the UI reflects changes automatically and vice versa (when a user changes the data in the UI the data in the business model is changed). </p>
<p>Binding establishes a connection between two dependant items. Basically, it is an automatic way of transferring information from one item to another.</p>
<p><strong>Content</strong></p>
<ul>
<li>Data Context, Dependency Property, Dependency Object </li>
<li>Types of Binding </li>
<li>Converters </li>
<li>Validation in Binding </li>
<li>Consuming Services </li>
<li>Sample </li>
</ul>
<h4>Data Context, Dependency Property, Dependency Object</h4>
<p><strong>Data Context</strong></p>
<p>In Data Binding we have two objects: target – the UI element and source – the data (business model, entity, etc). While the source property can be a normal .NET property, the target property must be a DependencyProperty. More on that later in the tutorial.</p>
<p>The DataContext is actually the source of data bound to the target. The default source of a binding is the data context. DataContext is inherited to child elements and thus ideal for scenarios where you want to bind multiple elements to a single data source. DataContext is a property of FrameworkElement. Let’s see this in an example:</p>
<pre class="brush: csharp;">

…

&lt;local:ContactCard  x:Name=&quot;JohnsBusinessCard&quot;
                            FullName=&quot;John Smith&quot;
                            Position=&quot;Silverlight Developer&quot;
                            Email=&quot;john@smith.com&quot; /&gt;

…

&lt;StackPanel DataContext=&quot;{StaticResource JohnsBusinessCard}&quot;&gt;
        &lt;TextBlock Text=&quot;{Binding FullName}&quot;
                   FontWeight=&quot;Bold&quot; /&gt;
        &lt;TextBlock Text=&quot;{Binding Position}&quot; /&gt;
        &lt;TextBlock Text=&quot;{Binding Email}&quot; /&gt;
    &lt;/StackPanel&gt;
</pre>
<p>ContactCard is a custom defined class with three properties – FullName, Position and Email.</p>
<p>All bindings set to the TextBlock elements inside the StackPanel have source the DataContext of the StackPanel &#8211; {StaticResource JohnsBusinessCard} in this case. </p>
<p>In case of items control we can think of the DataContext as the particular data item that we bind to at run time. So let’s say we have a list of ContactCard objects set as a DataContext to an ItemsControl. The data context of each of the items in the ItemsControl is the corresponding list element in the list (set as DataContext).</p>
<p><strong>Dependency Property and Dependency Object</strong></p>
<p>DependencyObject and DependencyProperty are fundamental concepts in Silverlight/WPF that provide the base for the underlying property system.  </p>
<p>< to be continued… > </p>
<p><strong>Types of Binding</strong></p>
<p>With each binding you can set Mode which defines the direction of the data flow as well as when the binding occurs. There are three available binding modes in Silverlight:</p>
<ol>
<li>OneTime – set the target and forget the binding. This mode is useful when you display data and you know that this data will never change or you don’t need to change it. Changes in the source are not propagated to the target. </li>
<li>OneWay – set the target and update it every time the source changes. This is the default mode. Use it in cases where the user can’t change the target, but you still want to keep the target updated once the source is changed from somewhere (say the code). </li>
<li>TwoWay – keep both the target and the source updated. Once the source is changed its new value is propagated to the target and vice versa. This is useful in cases where the user can change the target and you want the changes to be written back to the source.</li>
</ol>
<p>Lets take a look at the syntax:</p>
<pre class="brush: csharp;">

&lt;TextBlock Text=&quot;{Binding Email, Mode=TwoWay}&quot; /&gt; 
</pre>
<p>Depending on your case you can select one of the three binding modes. To choose which one is most appropriate for your case you can try to answer yourself the following questions in this order:</p>
<p>- Do I need to update the target when the source change? (yes &#8211; OneWay or TwoWay; no &#8211; OneTime)</p>
<p>- Do I need to reflect the changes done on the target to the source? (yes – TwoWay; no – OneWay)</p>
<p>< continue with INotifyPropertyChanged… ></p>
<h4>Converters</h4>
<p>A common scenario in data binding is that you need to format the data displayed to the user. Intuitive examples for that are formatting of DateTime and number values. In Silverlight and WPF this is achieved by applying a ValueConverter (or just Converter) to the data you are binding to. </p>
<p>Converters are classes that derive from the IValueConverter interface. This interface have two methods that should be implemented – Convert and ConvertBack. The Convert method is used when the data flows from the source to the target, while the ConvertBack is used when the data flows in the opposite direction – from the target to the source. In case your binding uses OneTime or OneWay mode you can go only with implementing the Convert method, but that is not considered a good practice as the converters are reusable chunks of code and you never know who and in what situation will use it.</p>
<p>Lets see what a converter look like:</p>
<pre class="brush: csharp;">

public class DateTimeConverter : IValueConverter
{
    public object Convert( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture )
    {
        DateTime dt = (DateTime)value;
        return dt.ToString( &quot;dd MMM, yyyy&quot;, culture );
    }
    public object ConvertBack( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture )
    {
        throw new NotImplementedException();
    }
}
</pre>
<p>Here only the Convert method is implemented. It is important to note that you should always validate the value parameter as it could not be from the type you expect. </p>
<p>// show the xaml syntax – convert as static resource</p>
<p>This is probably the most simplest converter you can ever write. The make it more flexible you can use a ConverterParameter. In different scenarios you may want to format the DateTime value in different way. The specific format can be passed through the ConverterParameter.</p>
<pre class="brush: csharp;">

&lt;TextBlock Text=&quot;{Binding Birthdate, Converter={StaticResource DateTimeConverter}, ConverterParameter=YYYY}&quot; /&gt; 
</pre>
<h4>Validation in Binding</h4>
<p>; content</p>
<h4>Consuming Services</h4>
<p>; content</p>
<h4>Sample</h4>
<p>; content</p>
]]></content:encoded>
			<wfw:commentRss>http://wsinsiders.com/2010/01/30/silverlight-tutorials-data-binding/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Silverlight Tutorials: Styling and Templating</title>
		<link>http://wsinsiders.com/2010/01/30/silverlight-tutorials-styling-and-templating/</link>
		<comments>http://wsinsiders.com/2010/01/30/silverlight-tutorials-styling-and-templating/#comments</comments>
		<pubDate>Sat, 30 Jan 2010 15:47:15 +0000</pubDate>
		<dc:creator>Michael Sync</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://wsinsiders.com/?p=264</guid>
		<description><![CDATA[This article is written by Alexander Golesh (Silverlight MVP). This is introduction to Silverlight styling and templating features. This is also the fifth chapter of “Silverlight Tutorials for Beginners” series. Content Styling Templating Conclusion Styling Silverlight controls has default look and feel, which is very close to standard Windows application look and feel. Style is [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>This article is written by <a href="http://blogs.microsoft.co.il/blogs/alex_golesh/">Alexander Golesh (Silverlight MVP)</a>.</p></blockquote>
<p>This is introduction to Silverlight styling and templating features. This is also the fifth chapter of  “<a href="http://wsinsiders.com/2010/01/29/silverlight-tutorials-for-beginners/">Silverlight Tutorials for Beginners</a>” series.</p>
<p><strong>Content</strong></p>
<ul>
<li>Styling</li>
<li>Templating</li>
<li>Conclusion</li>
</ul>
<h4>Styling</h4>
<p>Silverlight controls has default look and feel, which is very close to standard Windows application look and feel.</p>
<p><img title="1. Button Style" src="http://wsinsiders.com/wp-content/uploads/2010/01/1.-Button-Style.png" alt="" width="144" height="103" /></p>
<p>Style is a mechanism in Silverlight that allows you to encapsulate control property values as reusable resources. This is conceptually similar to CSS with HTML. Style defines control property values as reusable resources.</p>
<p>The same button which was used at figure 1 could have pretty non-standard look-and-feel.</p>
<p><img class="size-full wp-image-266 alignnone" title="2. Button" src="http://wsinsiders.com/wp-content/uploads/2010/01/2.-Button.png" alt="" width="123" height="45" /></p>
<p>Style also allows you to achieve same look-and-feel for multiple controls of the same type across all the application.</p>
<p>Let’s see how to create the style.<br />
Let’s create a simple button defining Button element in XAML inside the StackPanel:</p>
<pre class="brush: xml;">
&lt;Button Content=&quot;First Button&quot; Width=&quot;100&quot; Height=&quot;25&quot;/&gt;
</pre>
<p>Style defined in “Style” tag in XAML file as a part of some content resources. Placing a style inside a specific XAML page will enable its use in this specific content, while placing it in App.xaml will enable it to be reused across all pages and controls in application. Style also could be placed inside specific panel element, which will allow using this style only to the panel’s child elements. The style defined as a part of the Resources for chosen element.<br />
Sample style definition:</p>
<pre class="brush: xml;">
&lt;StackPanel.Resources&gt;
&lt;Style TargetType=&quot;Button&quot; x:Key=&quot;btnStyle&quot;&gt;
&lt;Setter Property=&quot;Width&quot; Value=&quot;100&quot;/&gt;
&lt;Setter Property=&quot;Height&quot; Value=&quot;25&quot;/&gt;
&lt;Setter Property=&quot;Background&quot; Value=&quot;Blue&quot;/&gt;
&lt;/Style&gt;
&lt;/StackPanel.Resources&gt;
</pre>
<p>In this case we defined the style as a part of some StackPanel, which will allow using this style only for child’s of this StackPanel. The style has 2 required attributes:</p>
<ol>
<li>TargetType – the Type of the element which allowed using this style. The type itself could specify the base class for the group of elements, for example ButtonBase – specifying it as TargetType enables to use this style for any derived class, like Button, RadioButton, CheckBox, etc.</li>
<li>x:Key – the name of the style, which will be used by the elements to access the style.</li>
</ol>
<p>Style defines the properties of the target element by specifying property name and the desired value in “Setter” element. In our case the style define values of 3 properties for the Button: Width, Height and Background.</p>
<p>Now it is a time to apply this style on our button:</p>
<pre class="brush: xml;">

&lt;Button Content=&quot;First Button&quot; Width=&quot;100&quot; Height=&quot;25&quot; Style=&quot;{StaticResource btnStyle}&quot;/&gt;
</pre>
<p>Style applied by specifying “Style” attribute of the desired element. Style (and not only style) specification uses special syntax called Markup Extension. This syntax is merely just a specification of some special command (in opposite of the attribute value, which usually being placed to the attribute) – in our case it is “StaticResource”. To distinguish special syntax from regular value it being placed inside curly braces “{…}”.</p>
<p>In our case StaticResource means that XAML parser should look for the resource named btnStyle and use the value of this resource as the value for the attribute.</p>
<p><img class="size-full wp-image-267 alignnone" title="3. Button" src="http://wsinsiders.com/wp-content/uploads/2010/01/3.-Button.png" alt="" width="115" height="43" /></p>
<p>Now our button has specified look. We could use this resource as many times as we need inside the scope of our style definition, and all elements with the same style will have same look and feel.</p>
<p><img class="size-full wp-image-268 alignnone" title="4. Button" src="http://wsinsiders.com/wp-content/uploads/2010/01/4.-Button.png" alt="" width="114" height="111" /></p>
<p>If we will change the definition in the style, all elements with this style applied will get the change:</p>
<pre class="brush: xml;">

&lt;Setter Property=&quot;Background&quot; Value=&quot;Green&quot;/&gt;
</pre>
<p><img class="size-full wp-image-269 alignnone" title="5. Button" src="http://wsinsiders.com/wp-content/uploads/2010/01/5.-Button.png" alt="" width="119" height="112" /></p>
<p>Any element could specify any property value at the element definition, and it will override the value given by style (if applied)</p>
<pre class="brush: xml;">

&lt;Button Content=&quot;First Button&quot; Width=&quot;100&quot; Height=&quot;25&quot; Style=&quot;{StaticResource btnStyle}&quot; Background=&quot;Red&quot;/&gt;
&lt;Button Content=&quot;Second Button&quot; Width=&quot;100&quot; Height=&quot;25&quot; Style=&quot;{StaticResource btnStyle}&quot;/&gt;
&lt;Button Content=&quot;Third Button&quot; Width=&quot;100&quot; Height=&quot;25&quot; Style=&quot;{StaticResource btnStyle}&quot;/&gt;
</pre>
<p><img class="size-full wp-image-270 alignnone" title="6. Button" src="http://wsinsiders.com/wp-content/uploads/2010/01/6.-Button.png" alt="" width="117" height="112" /></p>
<p>Style could “derive” from another style by using “BasedOn” attribute.</p>
<p>Let’s see how to define style hierarchy for the buttons, and how it behaves:</p>
<pre class="brush: xml;">

&lt;Style x:Key=&quot;BaseButtonStyle&quot; TargetType=&quot;Button&quot;&gt;
&lt;Setter Property=&quot;Width&quot; Value=&quot;100&quot;/&gt;
 &lt;Setter Property=&quot;Height&quot; Value=&quot;25&quot;/&gt;
&lt;Setter Property=&quot;Margin&quot; Value=&quot;5&quot;/&gt;
 &lt;/Style&gt;
&lt;Style x:Key=&quot;DerivedButtonStyle&quot; TargetType=&quot;Button&quot; BasedOn=&quot;{StaticResource BaseButtonStyle}&quot;&gt;
&lt;Setter Property=&quot;Background&quot; Value=&quot;Red&quot;/&gt;
 &lt;Setter Property=&quot;BorderBrush&quot; Value=&quot;Blue&quot;/&gt;
&lt;Setter Property=&quot;BorderThickness&quot; Value=&quot;3&quot;/&gt;
 &lt;/Style&gt; 

&lt;Style x:Key=&quot;ExtendedButtonStyle&quot; TargetType=&quot;Button&quot; BasedOn=&quot;{StaticResource DerivedButtonStyle}&quot;&gt;
&lt;Setter Property=&quot;ClickMode&quot; Value=&quot;Release&quot;/&gt;
&lt;Setter Property=&quot;Cursor&quot; Value=&quot;Hand&quot;/&gt;
 &lt;Setter Property=&quot;FontFamily&quot; Value=&quot;Trebuchet MS&quot;/&gt;
 &lt;Setter Property=&quot;FontSize&quot; Value=&quot;20&quot;/&gt;
 &lt;Setter Property=&quot;Height&quot; Value=&quot;35&quot;/&gt;
 &lt;Setter Property=&quot;Width&quot; Value=&quot;150&quot;/&gt;
 &lt;Setter Property=&quot;Background&quot; Value=&quot;Green&quot;/&gt;
 &lt;/Style&gt;
</pre>
<p>In this sample we created 3 styles for the Button type: ButtonBaseStyle, DerivedButtonStyle and ExtendedButtonStyle.</p>
<p>The DerivedButtonStyle uses BasedOn attribute to derive from ButtonBaseStyle. The BasedOn defined by using same Markup Extension syntax to define the parent style BasedOn=&#8221;{StaticResource BaseButtonStyle}&#8221;. The DerivedButtonStyle got all the properties defined in base style and adds 3 new properties. The ExtendedButtonStyle uses BasedOn attribute to derive from DerivedButtonStyle. It gets all the properties defined in DerivedButtonStyle and in ButtonBaseStyle, adds new property definitions and also overrides some of properties defined in base classes: Width, Height and Background.</p>
<p>Applied to the button will give use following look and feel:</p>
<p><img class="size-full wp-image-271 alignnone" title="7. Button" src="http://wsinsiders.com/wp-content/uploads/2010/01/7.-Button.png" alt="" width="172" height="122" /></p>
<p>The existing style could be applied not only by using Markup Extension in XAML, but also form code behind:</p>
<pre class="brush: csharp;">

Style style = this.Resources[&quot;BaseButtonStyle&quot;] as Style;

if (null != style)

btnSimple.Style = style;
</pre>
<p>The style itself also could be defined in code behind.</p>
<p>Let’s change the style of the button on the click event. The button definition:</p>
<pre class="brush: xml;">

&lt;Button Content=&quot;Set Style&quot; Click=&quot;Button_Click&quot; x:Name=&quot;btnNewButton&quot; Width=&quot;100&quot;/&gt;
</pre>
<p>The initial look:</p>
<p><img title="8. Button" src="http://wsinsiders.com/wp-content/uploads/2010/01/8.-Button.png" alt="" width="116" height="39" /></p>
<p>The event handler code:</p>
<pre class="brush: csharp;">

private void Button_Click(object sender, RoutedEventArgs e)
{
Style myStyle = new Style();
myStyle.TargetType = typeof(Button);

Setter setter = new Setter();
setter.Property = Button.BackgroundProperty;
setter.Value = new SolidColorBrush(Colors.Yellow);

myStyle.Setters.Add(setter);

btnNewButton.Style = myStyle;
}
</pre>
<p>And after the code being executed the button gets following look:</p>
<p><img title="9. Button" src="http://wsinsiders.com/wp-content/uploads/2010/01/9.-Button.png" alt="" width="119" height="41" /></p>
<p>The styling is powerful feature which allows us to configure basic set of properties for the element. But how it helps us to create the button which looks like this:</p>
<p><img title="10. Button" src="http://wsinsiders.com/wp-content/uploads/2010/01/10.-Button.png" alt="" width="123" height="45" /></p>
<p>The colors and fonts – we already know. But what about the shape of the button?</p>
<p>To completely change the UI for the element we have to use Template feature in Silverlight.</p>
<h4>Templating</h4>
<p>Template allows to completely customize/change the look and feel of the controls. It allows developers and designers to sculpt the UI of controls in both subtle and dramatic ways, and enables a tremendous amount of flexibility to create exactly the user experience desired.</p>
<p>Template could be created as a standalone resource (with same scope definitions like the styles) or templates could be created as a part of style for the control.<br />
The styles are the recommended location to create templates.</p>
<p>Templates created by defining “ControlTemplate” element with XAML.  Each template must define its “TargetType” (exactly like styles). In case of template definition as a standalone resource (not within a style) it also should have key defined within “x:Key” property.</p>
<p>Let’s define simple template for a button:</p>
<pre class="brush: xml;">

&lt;ControlTemplate TargetType=&quot;Button&quot; x:Key=&quot;roundButtonTemplate&quot;&gt;
&lt;Grid&gt;
&lt;Ellipse Width=&quot;200&quot; Height=&quot;200&quot;&gt;
&lt;Ellipse.Fill&gt;
&lt;RadialGradientBrush
GradientOrigin=&quot;0.2,0.2&quot;&gt;
&lt;GradientStop Offset=&quot;0.2&quot;
Color=&quot;White&quot;/&gt;
&lt;GradientStop Offset=&quot;1&quot;
Color=&quot;Red&quot;/&gt;
&lt;/RadialGradientBrush&gt;
&lt;/Ellipse.Fill&gt;
&lt;/Ellipse&gt;
&lt;TextBlock Text=&quot;Close&quot; FontSize=&quot;28&quot;
HorizontalAlignment=&quot;Center&quot;
VerticalAlignment=&quot;Center&quot;/&gt;
&lt;/Grid&gt;
&lt;/ControlTemplate&gt;
</pre>
<p>To apply the template on button use markup extension syntax (exactly like we did for styles):</p>
<pre class="brush: xml;">

&lt;Button Content=&quot;Hide Me&quot; Width=&quot;100&quot; Height=&quot;50&quot; FontSize=&quot;15&quot; Template=&quot;{StaticResource roundButtonTemplate}&quot;/&gt;
</pre>
<p><img title="11. Button Style" src="http://wsinsiders.com/wp-content/uploads/2010/01/11.-Button-Style.png" alt="" width="102" height="98" /></p>
<p>Well, the button is not exactly like planned – the text is “Close” (as defined in template) and not “Hide Me” (as defined in the control itself), the size of ellipse is also seems to be wrong. This behavior is because we didn’t specify that the values for those attributes should be taken from the actual control the style being applied on.<br />
In case of temple we could/should specify, that values for the attributes should be taken from the actual control. To do it we will use additional markup extension – “TemplateBinding”. Also, in a case of button (which is a Content Control), the text should be displayed as a content and not as a TextBlock. Let’s rewrite the ControlTemplate.</p>
<pre class="brush: xml;">&lt;/pre&gt;

&lt;ControlTemplate TargetType=&quot;Button&quot;
x:Key=&quot;fixedRoundButtonTemplate&quot;&gt;
&lt;Grid&gt;
&lt;Ellipse Width=&quot;{TemplateBinding Width}&quot;
 Height=&quot;{TemplateBinding Height}&quot;&gt;
&lt;Ellipse.Fill&gt;
&lt;RadialGradientBrush
GradientOrigin=&quot;0.2,0.2&quot;&gt;
&lt;GradientStop Offset=&quot;0.2&quot;
 Color=&quot;White&quot;/&gt;
&lt;GradientStop Offset=&quot;1&quot;
 Color=&quot;Green&quot;/&gt;
&lt;/RadialGradientBrush&gt;
&lt;/Ellipse.Fill&gt;
&lt;/Ellipse&gt;
&lt;ContentPresenter Content=&quot;{TemplateBinding Content}&quot; HorizontalAlignment=&quot;Center&quot; VerticalAlignment=&quot;Center&quot;/&gt;
&lt;/Grid&gt;
&lt;/ControlTemplate&gt;
</pre>
<p>When applied to the button</p>
<pre class="brush: xml;">

&lt;Button Content=&quot;Exit&quot; Width=&quot;100&quot; Height=&quot;50&quot; FontSize=&quot;15&quot; Template=&quot;{StaticResource fixedRoundButtonTemplate}&quot;/&gt;
</pre>
<p><img title="12. Button Green" src="http://wsinsiders.com/wp-content/uploads/2010/01/12.-Button-Green.png" alt="" width="102" height="85" /></p>
<p>The button looks like expected.</p>
<p>The ControlTemplate definition as a part of a style should be in a value of Template property.</p>
<p>Sample (partial) style definition:</p>
<pre class="brush: xml;">

&lt;Style x:Key=&quot;buttonStyle&quot; TargetType=&quot;Button&quot;&gt;
&lt;Setter Property=&quot;Padding&quot; Value=&quot;4&quot; /&gt;
&lt;Setter Property=&quot;FontFamily&quot; Value=&quot;Trebuchet MS&quot;/&gt;
&lt;Setter Property=&quot;FontSize&quot; Value=&quot;12&quot;/&gt;
&lt;Setter Property=&quot;Template&quot;&gt;
&lt;Setter.Value&gt;
&lt;ControlTemplate TargetType=&quot;Button&quot;&gt;
&lt;Grid&gt;
...
</pre>
<p>Then, applying the “buttonStyle” on the button will change the Button’s properties and the button template according to defined in style.<br />
When utilizing Control Templates, the templated control still has all the functionality of the original control (in the case of button it is click, mouse hover, etc.)</p>
<h4>Conclusion</h4>
<p>The styling and templating are a very powerful feature, which allows to completely customize standard look and feel for any custom control.</p>
]]></content:encoded>
			<wfw:commentRss>http://wsinsiders.com/2010/01/30/silverlight-tutorials-styling-and-templating/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Tutorials: Introduction of Silverlight</title>
		<link>http://wsinsiders.com/2010/01/30/tutorials-introduction-of-silverlight/</link>
		<comments>http://wsinsiders.com/2010/01/30/tutorials-introduction-of-silverlight/#comments</comments>
		<pubDate>Sat, 30 Jan 2010 15:21:35 +0000</pubDate>
		<dc:creator>Michael Sync</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://wsinsiders.com/?p=144</guid>
		<description><![CDATA[This article is written by Braulio Diez Botella (Silverlight MVP) and Michael Sync (Silverlight MVP) This is the first chapter of  &#8220;Silverlight Tutorials for Beginners&#8221; series. This chapter will give you the overview of Silverlight and some basic information that will help you to get started with Silverlight. Contents What is Silverlight? Why Silverlight? Installing [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>This article is written by <a href="http://geekswithblogs.net/braulio/Default.aspx">Braulio Diez Botella (Silverlight MVP)</a> and <a href="http://michaelsync.net">Michael Sync (Silverlight MVP)</a></p></blockquote>
<p>This is the first chapter of  &#8220;<a href="http://wsinsiders.com/2010/01/29/silverlight-tutorials-for-beginners/">Silverlight Tutorials for Beginners</a>&#8221; series. This chapter will give you the overview of Silverlight and some basic information that will help you to get started with Silverlight.</p>
<p><strong>Contents</strong></p>
<ul>
<li>What is Silverlight?</li>
<li>Why Silverlight?</li>
<li>Installing Silverlight 3</li>
<li>Silverlight 3 &#8211; Hello World</li>
<li>History of Silverlight</li>
<li>Conclusion</li>
<li>References</li>
</ul>
<h4>What is Silverlight?</h4>
<p>Silverlight is a cross-platform web presentation technology for building Rich Internet Business or Media Applications that runs on various platforms (e.g. Windows, Linux, Mac ) and devices (e.g. Windows Mobile, Nokia S60). It&#8217;s also a subset of Windows Presentation Framework (WPF) so if you are already familiar with WPF then it&#8217;s very easy for you to learn Silverlight. You can imagine that Silverlight is something similar to Flash. Flash is mainly being used for Media-related applications such as video and online gaming but you can use Silverlight for both Line-of-Business Applications and Media related applications.</p>
<h4>Why Silverlight?</h4>
<p>Nowdays there are many web and RIA technologies available (ASP .net, PHP, AJAX ASP .net, Flash, Flex, &#8230;), Why should we bother about a new kid in town? If we compare desktop development with web development, we find that the second one has evolved rapidly: some years ago users were used to fill plain forms with limited functionality, nowdays they are requesting web app&#8217;s with a similar level of usability than a Win Forms / WPF application, altough this goal can be achieved with current technologies we found several challenges and limitations:</p>
<ul>
<li>HTML is a technology that has grown organically, the basis of this technology are not targeted for the current expectations, the community has been asking for enhancements and they have been put on top of the existing basement.</li>
<li>Javascript is as well an outdated language, originally targeted to run on any old cheap computer, not compiled, not fully object oriented, and each browser has it owns implementation.</li>
<li>Developing a web project means developing on different technologies and languages, e.g.: server side C# + .net framework, client side HTML + javascript.</li>
<li>Implementing a site using partial rendering (UpdatePanel) it&#8217;s a very limited way to implement AJAX on your application and can lead you to serious performance issues.</li>
<li>Implementing a site using a pure AJAX approach (e.g. script service) can become a complex task, too much Javascript, prone to errors and hard to maintain.</li>
<li>Unlike  other RIA technologies, Silverlight offers a specialized IDE for developers (Visual Studio) and a specialized IDE for UI Designers (Expression Blend). It’s also based on solid and mature programming languages (C#, VB .net, …)</li>
</ul>
<p>What can we expect from Silverlight, does it break these limitations ? Let&#8217;s enumerate some of the strengths of this new technology:</p>
<p><strong><span style="text-decoration: underline;">Technically Speaking</span></strong></p>
<ul>
<li>XAML modern markup declarative language (solid foundation).</li>
<li>Enables you to build real OOP code on the client side.</li>
<li>The code is compiled.</li>
<li>Less browser compatibility issues (same plugin for different browsers).</li>
<li>You get the benefit o having the .net framework available on the client side.</li>
<li>It contains Powerful components and user controls.</li>
<li>you can use same technology / languages on the client and server side (e.g. code your full app on C#).</li>
<li>Familiar IDE (Visual Studio).</li>
<li>Fully integration with designers and separations of concerns (XAML, Code behind, Declarative Binding).</li>
</ul>
<p><strong><span style="text-decoration: underline;">From the customer perception</span></strong></p>
<ul>
<li><strong>Usability</strong>: Break the limitations of HTML, build rich user interface applications, perform communications with the server faster (no more post, direct service communication)</li>
<li><strong>Maintainability</strong>: Same technology used on the server and client side (C# / VB .net &#8230; plus .net framework), ability to build a solid pattern on the client side (MVVM, MVP, &#8230;) and add automated unit testing.</li>
<li><strong>Scalability</strong>: Silverlight applications run on the client side, that means free resources on the server instances (no more server side script to HTML transformations, post processing, &#8230;).</li>
<li><strong>Availability</strong>: Silverlight applications can run as out of browser app&#8217;s (no need to rely on the server to launch it) and incorporate mechanisms to detect network current network status (ability to build a &#8220;work offline&#8221; model).</li>
<li><strong>Extensibility</strong>: Applications can be divided into several XAP and loaded on demand, it&#8217;s possible to implement plugin extensions on a given app.</li>
<li><strong>Security</strong>: You can decide whether to use the existing browser security (inherit security from your existing web application) or define your custom security.</li>
<li><strong>Portability</strong>: Silverlight is cross browser (FireFox, Safari, IE), cross Plaftorm (Windows, Mac OS), multi device (Mobile coming soon).</li>
</ul>
<h4>Installing Silverlight</h4>
<p>Here is the list of installers that you need to install before start playing with Silverlight ~</p>
<ul>
<li><a href="http://go.microsoft.com/fwlink/?LinkID=143571" target="_blank">Silverlight 3 Beta Tools for Visual Studio 2008</a> : This installer is the combination of Silverlight runtime, Silverlight SDK and Visual Studio Template for Visual Studio 2008. If you like to use Visual Studio for developing Silverlight, you must install this installer in your machine. Here are the few things that you should note before installing ~
<ul>
<li>you must have <strong><span style="text-decoration: underline;">Visual Studio 2008 (any edition) with service pack 1</span></strong> installed before installing this installer.</li>
</ul>
<ul>
<li>The prior version of Visual Studio 2008 is not supported.</li>
</ul>
<ul>
<li>You can&#8217;t have multiple versions of Silverlight installed in one machine.</li>
</ul>
<ul>
<li>You need to have an internet connection to install this installer. Otherwise, extract it by using winrar and install one by one.</li>
</ul>
<ul>
<li>You need to close Visual Studio and all browsers on your machine.</li>
</ul>
</li>
</ul>
<ul>
<li><a href="http://www.microsoft.com/expression/blendpreview">Expression Blend 3 Preview</a> : This is an optional installer. You don&#8217;t need to install it if you don&#8217;t want but Blend can help you to design the look and feel of your application in very easy way. The XAML designer for Silverlight in Visual Studio sucks. You can&#8217;t even drag and drop any control on that designer. This is where Blend can come in and help you in designing the UI.</li>
</ul>
<p>Yes. You can start installing them now. and come back here when you have finished installing. Note that there are other useful tools (<a href="http://www.codeplex.com/Silverlight">Silverlight Toolkit</a>,  <a href="http://go.microsoft.com/fwlink/?LinkId=144609">RIA Services</a>, <a href="http://www.microsoft.com/downloads/details.aspx?familyid=457b17b7-52bf-4bda-87a3-fa8a4673f8bf&amp;displaylang=en" target="_blank">Deep Zoom Composer</a>, <a href="http://www.microsoft.com/web/" target="_blank">Microsoft Web Platform Installer</a> and etc) that you can download and install but we will probably install later since you don&#8217;t need them now.</p>
<h4>Important Notes</h4>
<p>Okay. You are back now? How was the installation? Please leave the comment in this post or ask <a title="Official Microsoft Silverlight Forum" href="http://silverlight.net/forums/">there</a> if you have any problem in installation. As of now, I&#8217;ll just hope that you have installed Silverlight 3 Tools successfully. Let&#8217;s continue&#8230;</p>
<p>There are three important things that you have to keep in mind when you are working on Silverlight.</p>
<ul>
<li><strong>Desktop CLR Vs Silverlight CLR</strong> : The first thing that you need to know is that .NET CLR and Slverlight CLR are totally different. The assembly that you compile with Silverlight CLR won&#8217;t be compatible with .NET CLR.</li>
</ul>
<ul>
<li><strong>Re-using your .NET Class Library in Silverlight</strong>: You can&#8217;t reference a .NET assembly in Silverlight. Remember what I just told you? .NET CLR and Silverlight CLR are different so the binary are not compatible between them. That&#8217;s why you can&#8217;t add the .NET assembly as a reference in Silverlight.If you like to re-use your .NET class library in Silverlight, you will have to port it to Silverlight (like I did for <a href="http://michaelsync.net/2008/07/11/unity-application-block-unity-for-silverlight-and-stoplight-quickstart">Unity Framework</a> before Microsoft release Unity 1.2 that supports Silverlight). How can we port .NET Library to Silverlight? it&#8217;s very simple. First, you need to create Silverlight project in Visual Studio. And, copy some or all of your files from .NET project to Silverlight project. Then, fix the error and find the workaround for those codes that are not supported in Silverlight.As <a href="http://msdn.microsoft.com/en-us/library/cc838194(VS.96).aspx">.NET Framework Class Library for Silverlight</a> are very small compared to <a href="http://msdn.microsoft.com/en-us/library/ms229335.aspx">.NET Framework Class Library (desktop version)</a>, there are a lot of classes, properties, methods, events and etc which are missing in Silverlight. But normally, there are some ways to workaround to get the same functionalities in Silverlight. You can take a look at my <a href="http://michaelsync.net/2009/03/22/silverlight-3-array-helper">Array Helper class</a> that I created when I was porting <a href="http://michaelsync.net/2008/07/11/unity-application-block-unity-for-silverlight-and-stoplight-quickstart">Unity Framework</a>.</li>
</ul>
<ul>
<li><strong>Sandbox Security</strong> : Silverlight runs in a <a href="http://en.wikipedia.org/wiki/Sandbox_(computer_security)">sandbox</a> so that you won&#8217;t be able to access the user&#8217;s hard drive (except Isolated Storage), registry and etc regardless of whether your Silverlight application is runing in browser or out of browser. (Don&#8217;t worry if you don&#8217;t understand what I meant by &#8220;Isolated Storage&#8221; or &#8220;Out-Of-Browser Silverlight Application&#8221;. )</li>
</ul>
<p>Let&#8217;s create a &#8220;Hello World&#8221; program in Silverlight.</p>
<h4>Silverlight &#8211; Hello World</h4>
<p>Open Visual Studio 2008 and click on New Project ( File -&gt; New -&gt; Project) dialog. You will see new project type called &#8220;Silverlight&#8221; under &#8220;Project Type&#8221; tree. If you click on that node, you will see four project tamplates for Silverlight as below. I&#8217;m not going to tell you about the details of each project template but I promise that I will definitely tell you later. As of now, Let&#8217;s choose &#8220;Silverlight Application&#8221;, give the name of project and specify the path that you want this project to be created.</p>
<p><img class="aligncenter size-full wp-image-1464" title="Silverlight Project Template" src="http://michaelsync.net/wp-content/uploads/2009/07/Silverlight-Project-Template.jpg" alt="Silverlight Project Template" width="515" height="310" /></p>
<p>I will use &#8220;SilverlightApplication1&#8243; as name of my project and will create it under Silverlight Tutorials folder. And then, I will click on &#8220;OK&#8221; button.</p>
<p><img class="aligncenter size-full wp-image-1465" title="Silverlight Tutorials - Give the project name" src="http://michaelsync.net/wp-content/uploads/2009/07/Silverlight-Tutorials-Give-the-project-name.jpg" alt="Silverlight Tutorials - Give the project name" width="513" height="414" /></p>
<p>The dialog below will be shown for you to choose how you want to host your Silverlight application. Ticking on the checkbox for &#8220;Host the Silverlight application in a new Web Site&#8221; means Visual Studio will generate one Silverlight Application project and ASP.NET project that you can use for hosting Silverlight content in ASPX page. We will untrick this checkbox since we don&#8217;t need to have any ASP.NET website. You may ask that where we are going to host our Silverlight content if we don&#8217;t have any web site. Nothing to worry. Visual Studio will automatically generate a html page with your Silverlight content embedded when you are building the application.</p>
<p><img class="aligncenter size-full wp-image-1466" title="Silverlight Tutorial - Chosing Silverlight Host and RIA" src="http://michaelsync.net/wp-content/uploads/2009/07/Silverlight-Tutorial-Chosing-Silverlight-Host-and-RIA.jpg" alt="Silverlight Tutorial - Chosing Silverlight Host and RIA" width="448" height="398" /></p>
<p>The checkbox under &#8220;Options&#8221; panel is used for enabling .NET RIA Services that is introduced with Silverlight 3. Using .NET RIA Service is out of scope of this tutorial series. But there will be another tutorial series for .NET RIA Service in this website. (Please wish me to get more time to write for you guys and wish my wife to be happy <img src='http://wsinsiders.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  ). After unticking both checkboxes, the appearnace of dialog will change as below. Please click on &#8220;OK&#8221; button.</p>
<p><img class="aligncenter size-full wp-image-1467" title="Silverlight Tutorial - No ASP.NET and No RIA" src="http://michaelsync.net/wp-content/uploads/2009/07/Silverlight-Tutorial-No-ASP.NET-and-No-RIA.jpg" alt="Silverlight Tutorial - No ASP.NET and No RIA" width="448" height="266" /></p>
<p>Your brand new Silverlight application will be generated as below in Visual Studio.</p>
<h4>Understanding of Silverlight File Structure</h4>
<p>If you look at Solution Explorer, you will see the list of files as below. I will brief you a bit about each file.</p>
<p><img class="aligncenter size-full wp-image-1468" title="Silverlight Tutorial - Simple Silverlight File Structure" src="http://michaelsync.net/wp-content/uploads/2009/07/Silverlight-Tutorial-Simple-Silverlight-File-Structure.jpg" alt="Silverlight Tutorial - Simple Silverlight File Structure" width="297" height="426" /></p>
<p><strong>1. AppManifest.xml</strong> : This is the application manifest file that is required to generate the application package. You don&#8217;t need to edit anything in this file for the most of times unless you want to add &#8220;Offline&#8221; support in your project.</p>
<p><strong>2. AssemblyInfo.cs</strong> : If you already have some experiences in .NET, I&#8217;m sure that you already know what you can do in this file. This is where you can define the information (e.g. version number, description and etc) for your Silverlight assembly.</p>
<p><strong>3. App.xaml and App.xaml.cs</strong></p>
<p><strong>Entry Point</strong> : This is an default entry point of your application and it will instantiate the application object. The reason why this file is an default entry point is that the BuildAction of this file is set to &#8220;<strong>ApplicationDefinition</strong>&#8221; by default. On the startup of App, you can set the RootVisual to any XAML page (e.g. MainPage() in our case) that you want to show to the user.</p>
<p>For example:</p>
<pre class="brush: csharp;">
private void Application_Startup(object sender, StartupEventArgs e)
{
this.RootVisual = new MainPage();
}
</pre>
<p><strong>Application-wide Resources</strong> : You can also define any resouces that you want to be available in your whole application.</p>
<p><strong>4. MainPage.xaml</strong></p>
<p>This is a user control that will be shown on the browser. As you set this page as a RootVisual in App, it will be the first page that you will see on browser at runtime.</p>
<p>Okay. I hope you get some idea about Silverlight default file structure and what you can do with those files. Let&#8217;s get back to the &#8220;Hello World&#8221; sample that we are doing.</p>
<p>Open MainPage.xaml and drag one button from Toolbox to the XMAL file.</p>
<p><img class="aligncenter size-full wp-image-1469" title="Silverlight Tutorials - Button on Toolbar" src="http://michaelsync.net/wp-content/uploads/2009/07/Silverlight-Tutorials-Button-on-Toolbar.jpg" alt="Silverlight Tutorials - Button on Toolbar" width="420" height="245" /></p>
<p>and write &#8220;Click Me&#8221; in the content of that button as below.</p>
<pre class="brush: xml;">
&lt;UserControl x:Class=&quot;SilverlightApplication1.MainPage&quot;
 xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
 xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
 xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot; xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;
 mc:Ignorable=&quot;d&quot; d:DesignWidth=&quot;640&quot; d:DesignHeight=&quot;480&quot;&gt;
 &lt;Grid x:Name=&quot;LayoutRoot&quot;&gt;
 &lt;Button Content=&quot;Click Me&quot; Click=&quot;Button_Click&quot;&gt;&lt;/Button&gt;
 &lt;/Grid&gt;
&lt;/UserControl&gt;
</pre>
<p>After that, we will write a MessageBox in that click event.</p>
<pre class="brush: csharp;">
private void Button_Click(object sender, RoutedEventArgs e)
{
  MessageBox.Show(&quot;Hello World&quot;);
}
</pre>
<p>Now, your application is ready to run. So, press F5 to run the application. Your &#8220;Hello World&#8221; program will be displayed on your default browser. If you click on &#8220;Click Me&#8221; button then you will get this message box &#8220;Hello World!&#8221; as shown in the screenshot below.</p>
<p><img class="aligncenter size-full wp-image-1473" title="Silverlight Tutorials - Hello World" src="http://michaelsync.net/wp-content/uploads/2009/07/Silverlight-Tutorials-Hello-World.jpg" alt="Silverlight Tutorials - Hello World" width="493" height="477" /></p>
<p>Yeahh.. You have successfully created very first Silverlight application.  There are a few more tutorials in this series and I&#8217;m sure that you will be able to start working on your own Silverlight once you have finished reading all chapters in this series.</p>
<p>Don&#8217;t hesitate to contact us or drop a comment in this post if you have any question or difficulties or feeback or anything.</p>
<p>Hope it helps.</p>
<p>Happy Silverlighting!!</p>
<p><strong>References ~</strong></p>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/cc526062.aspx">Introducing Microsoft Silverlight 1</a> (should be 1 instead of 1.0. &#8220;We are integer, babe!&#8221;)</li>
<li><a href="http://msdn.microsoft.com/en-us/library/cc838158(VS.95).aspx">Silverlight 2</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/cc838158(VS.96).aspx">Silverlight 3</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://wsinsiders.com/2010/01/30/tutorials-introduction-of-silverlight/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Silverlight Tutorials for Beginners</title>
		<link>http://wsinsiders.com/2010/01/29/silverlight-tutorials-for-beginners/</link>
		<comments>http://wsinsiders.com/2010/01/29/silverlight-tutorials-for-beginners/#comments</comments>
		<pubDate>Sat, 30 Jan 2010 06:35:23 +0000</pubDate>
		<dc:creator>Michael Sync</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://wsinsiders.com/?p=142</guid>
		<description><![CDATA[This is our first series of tutorials for those who are new to Silverlight. I would like to thank Braulio Diez Botella,  Alexander Golesh,  Emil Stoychev,  Einar Ingebrigtsen and Daron Yöndem for contributing their articles for this series. Special thanks to Jocelyn Mae Villaraza from Microsoft Singapore for reviewing our articles. 1. Introduction of Silverlight [...]]]></description>
			<content:encoded><![CDATA[<p>This is our first series of tutorials for those who are new to Silverlight. I would like to thank <strong><a href="http://geekswithblogs.net/braulio/Default.aspx">Braulio Diez Botella</a>,  <a href="http://blogs.microsoft.co.il/blogs/alex_golesh/">Alexander Golesh</a>,  <a href="http://emil.silverlightshow.net/">Emil Stoychev</a>,  <a href="http://www.ingebrigtsen.info/">Einar Ingebrigtsen</a> </strong>and<strong> <a href="http://daron.yondem.com/">Daron Yöndem</a></strong> for contributing their articles for this series. Special thanks to <a href="http://aimeegurl.com/">Jocelyn Mae Villaraza</a> from Microsoft Singapore for reviewing our articles.</p>
<h4>1. Introduction of Silverlight</h4>
<p>- By Braulio Diez Botella and Michael Sync</p>
<p><strong>URL</strong> : <a href="http://wsinsiders.com/2010/01/30/tutorials-introduction-of-silverlight/">http://wsinsiders.com/&#8230;-introduction-of-silverlight/</a></p>
<ul>
<li>Introduction of Silverlight</li>
<li>What is Silverlight?</li>
<li>Why Silverlight?</li>
<li>Installing Silverlight</li>
<li>Silverlight  &#8211; Hello World</li>
<li>Reference</li>
</ul>
<h4>2. XAML Basic</h4>
<p>- Michael Sync</p>
<p><strong>URL</strong> : <em>Coming Soon</em>.</p>
<ul>
<li>XAML Basic</li>
<li>What is XAML?</li>
<li>Basic Syntax</li>
<li>XAML vs Code</li>
<li>Instantiating object in XAML</li>
<li>Namespace</li>
<li>Resources</li>
</ul>
<h4>3. Silverlight Basic</h4>
<p>- Daron Yondem, Einar Ingebrigtsen</p>
<p><strong>URL</strong> : <a href="http://wsinsiders.com/2010/01/30/silverlight-tutorials-silverlight-basic-spinningcube/">http://wsinsiders.com/&#8230;-spinningcube/</a></p>
<p><em>Note: Daron&#8217;s tutorial will be published soon.</em></p>
<ul>
<li>Silverlight Basic</li>
<li>Layout</li>
<li>Controls</li>
<li>Events</li>
<li>HTML Bridges</li>
<li>Media &#8211; Audio/Video/Graphics</li>
<li>3D object</li>
<li>Sample</li>
</ul>
<h4>4. Data Binding</h4>
<p>- Emil Stoychev</p>
<p><strong>URL</strong> : <a href="http://wsinsiders.com/2010/01/30/silverlight-tutorials-data-binding/">http://wsinsiders.com/&#8230;-data-binding/</a></p>
<p><em>Note: This article has not finished yet. The update will be published very soon. Stay turned.</em></p>
<ul>
<li>Data-Binding</li>
<li>Data Context and Dependency Property, Dependency Object</li>
<li>Types of Binding</li>
<li>Converter</li>
<li>Validation in Binding</li>
<li>Consuming Services</li>
<li>Sample</li>
</ul>
<h4>5. Styles/Templates</h4>
<p>- Alexander Golesh</p>
<p><strong>URL</strong> : <a href="http://wsinsiders.com/2010/01/30/silverlight-tutorials-styling-and-templating/">http://wsinsiders.com/&#8230;-styling-and-templating/</a></p>
<ul>
<li>Styles</li>
<li>Basic understanding about Style</li>
<li>Control Template and Data Template</li>
<li> Based On</li>
<li>Style in Resource File/ Merging/ Theme</li>
<li>Sample</li>
</ul>
<p>We are planning to write more tutorials for our Silverlight community. If you like to see any specific topic or you like to participate in writing tutorials, please let me know. I can be reached at mchlsync AT gmail DOT com.  Thanks.</p>
]]></content:encoded>
			<wfw:commentRss>http://wsinsiders.com/2010/01/29/silverlight-tutorials-for-beginners/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Under Construction</title>
		<link>http://wsinsiders.com/2009/07/30/under-construction/</link>
		<comments>http://wsinsiders.com/2009/07/30/under-construction/#comments</comments>
		<pubDate>Thu, 30 Jul 2009 14:16:02 +0000</pubDate>
		<dc:creator>Michael Sync</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://wsinsiders.com/?p=134</guid>
		<description><![CDATA[This is under construction. Please come back and check again.]]></description>
			<content:encoded><![CDATA[<p>This is under construction. Please come back and check again. </p>
]]></content:encoded>
			<wfw:commentRss>http://wsinsiders.com/2009/07/30/under-construction/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

