Showing posts with label WPF. Show all posts
Showing posts with label WPF. Show all posts

Wednesday, July 9, 2008

Differences between WPF and Silverlight

Nowadays, two terms are mostly heard in Windows Graphics sphere, WPF and Silverlight. Many of us presume they are one and the same thing. But actually there are fundamental differences between the two. In this post, I'm posting the basic differences between the two (primarily Silverlight 1.x)
WPFSilverlight 1.x
WPF is the complete graphics framework written from the scratch by MicrosoftSilverlight is subset of WPF in the sense that it contains only windows independent class libraries of WPF
WPF applications are not Web enabled. They are mostly focused around Windows FormsSilverlight has been introduced for the sole purpose of enabling Web support for WPF applications
WPF applications are supported by only Windows based computersSilverlight provides support for different browsers like Firefox and Safari
WPF applications whole heartily support and use C#Silverlight applications use XAML and Javascript to define their markup and behaviour. C# code is not supported
WPF requires .NET runtimeSilverlight doesn't require .NET runtime to render its graphics
WPF uses Windows media player on the client to play any mediaSilverlight uses OS media support to play media
WPF has capability to create 3D graphicsSilverlight is limited to 2D graphics only

Essential XAML Simplified 2

As we have seen in the previous post XAML provides new generation of opportunities by which we can describe an object. Here we'll cover the remaining two concepts

  • Attached Properties
  • Markup Extensions

Going back to previous example of TextBlock which is shown below

<TextBlock Text="Title:" Style="{StaticResource TextBlockStyle}"

Grid.Row="0" Grid.Column="0" HorizontalAlignment="Right"></TextBlock>

Attached Properties refers to the ability by which child objects can set properties of parent object. In this control Grid (parent control) contains this TextBlock (child control). The way it helps is child elements inform the parent element of how they are to be presented in the user interface (UI). Another possiblity is different child elements unique values for the same parent element depending their own suitability. A point not be missed here is that a control which sports Attached Properties should implement them as Dependency properties in it own definition.

Alright! Markup Extensions.

Basically it refers to the attribute value being picked up from a collection which is described elsewhere. In the above example the Collection of StaticResource(s) can be put inside App.xaml (which is common markup for all your applications in the assembly) like this

<Application.Resources>

<Style x:Key="TextBlockStyle" TargetType="TextBlock">

<Setter Property="ForeGround" Value="Black"></Setter>

<Setter Property="Margin" Value="2"></Setter>

</Style></Application.Resources>

Similar we can have a Binding Markup like

Text="{Binding QuantityOnHand}"

where QuantityOnHand is column in an IEnumerable collection.

Monday, June 9, 2008

Essential XAML Simplified 1

Today we'll touch the three most lauded concepts introduced by the XAML (eXtensible Application Markup Language). XAML to me seems like XML + .NET. By that I mean XAML provides you the best of both worlds by leveraging descriptive nature of XML and object-oriented nature of .NET. It allows you to instantiate a .NET object like WatermarkedTextbox and describe it properties using pure XML driven syntax, and all that in the Markup. So lets go ahead and explore these three majestic Xaml concepts :

  1. Property Element Syntax
  2. Attached Properties
  3. Markup Extensions

Property Element Syntax

Basically in XAML markup we have three types of element syntaxes

  • Object Element Syntax
  • Attribute Element Syntax
  • Property Element Syntax

To understand them one by one, lets take an example of the a simple WPF control, the TextBlock

<TextBlock Text="Title:" Style="{StaticResource TextBlockStyle}"

Grid.Row="0" Grid.Column="0" HorizontalAlignment="Right"></TextBlock>

Object element syntax refers to the way we have instantiated a .NET object ie TextBlock. Attribute element syntax means to how have used XML attributes (like HorizontalAlignment above) to define that object's properties and given it a value (ie Right). Now assume for a while that we have a TextBlock that displays a custom drawing instead of just plain text. Such TextBlock definition will look like this

<TextBlock Style="{StaticResource TextBlockStyle}" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Right">

<TextBlock.Text>

<Canvas>..Drawing here...</Canvas>

</TextBlock.Text>

</TextBlock>
Property Element syntax pertains the way have defined the TextBlock's property comprehensively (a detailed drawing object) instead of just a word "Title:". So this ability of XAML to support myriad of property definitions is branded by the magic word "Property Element Syntax". Just for the sake of readability we'll cover the next 2 concepts in the subsequent post which can be found here