Skip to main content

WPF Overview-Part-I

Windows presentation foundation (WPF) presents a unique paradigm that enables designers and developers to work independently and later on merge the work. This is facilitated by XAML (read more about XAML here) and the usual code behind file. WPF has a separate architecture (details here), that needs to be understood before diving into the fancy terms like dependency properties, Bindings etc.

Let us start with a quick review of Architecture.PresentationCore and Presentation Framework is the two main components that do most of the work in WPF. The Diagram below, depicts the complete architecture(This has been taken from MSDN)



 There are three dlls which makes the Windows Presentation Foundation, that is WindowsBase (WindowsBase.dll), PresentationCore (PresentationCore.dll), and PresentationFoundation (PresentationFoundation.dll).

First WPF component is milcore. MIL stands for Media Integration Layer. MIL is interface between DirectX and CLR (plus above layer). MILCORE is unmanaged component which handles the 2D, 3D , Animation with the help of DirectX. WPF uses MILCORE for rendering purpose. MILCORE is also known as composition engine.

WindowsBase defines most of the Base type which are used in WPF. Hence for any WPF Application, WindowsBase library is must be a part of the solution. Second component is PresentationCore (PresentationCore.dll). This DLL doesn’t hold any UI component but it contains the base types which can be used in implementing the UI component .

PresentationFoundation contains all the WPF controls and manages other useful WPF functionality. This provides the presentation on the screen.

 After architecture, following are the concepts that need to be understood for getting a good grasp of WPF

  1. Layout System

  2. Dependency Properties

  3. Routed Events

  4. Data Binding


Layout System

These are the five most popular layout panels of WPF:























Grid PanelThe grid is a layout panel that arranges its child controls in a tabular structure of rows and columns. Its functionality is similar to the HTML table but more flexible. A cell can contain multiple controls; they can span over multiple cells and even overlap themselves.

The resize behavior of the controls is defined by the HorizontalAlignment and VerticalAlignment properties who define the anchors. The distance between the anchor and the grid line is specified by the margin of the control
Stack PanelThe StackPanel in WPF is a simple and useful layout panel. It stacks its child elements below or beside each other, depending on its orientation. This is very useful to create any kinds of lists

<StackPanel>

  <TextBlock Margin="10" FontSize="20">How do you like your coffee?</TextBlock>

  <Button Margin="10">Black</Button>

  <Button Margin="10">With milk</Button>

  <Button Margin="10">Latte</Button>

  <Button Margin="10">Cappuccino</Button>

</StackPanel>
Dock PanelThe dock panel is a layout panel, that provides an easy docking of elements to the left, right, top, bottom or center of the panel. The dock side of an element is defined by the attached property DockPanel.Dock. To dock an element to the center of the panel, it must be the last child of the panel and the LastChildFill property must be set to true
<DockPanel LastChildFill="True">
    <Button Content="Dock=Top" DockPanel.Dock="Top"/>
    <Button Content="Dock=Bottom" DockPanel.Dock="Bottom"/>
    <Button Content="Dock=Left"/>
    <Button Content="Dock=Right" DockPanel.Dock="Right"/>
    <Button Content="LastChildFill=True"/>
</DockPanel>

 
Wrap PanelThe wrap panel is similar to the stackPanel but it does not just stack all child elements to one row, it wraps them to new lines if no space is left. The Orientation can be set to Horizontal or Vertical.

The WrapPanel can be used to arrange tabs of a tab control, menu items in a toolbar or items in an Windows Explorer like list
<WrapPanel Orientation="Horizontal">
    <Button Content="Button" />
    <Button Content="Button" />
    <Button Content="Button" />
    <Button Content="Button" />
    <Button Content="Button" />
</WrapPanel>

 
Canvas PanelThe Canvas is the most basic layout panel in WPF. Its child elements are positioned by explicit coordinates. The coordinates can be specified relative to any side of the panel using the Canvas.Left, Canvas.Top, Canvas.Bottom and Canvas.Right attached properties.

The panel is typically used to group 2D graphic elements together and not to layout user interface elements. This is important because specifying absolute coordinates brings you in trouble when you begin to resize, scale or localize your application.
<Canvas>
    <Rectangle Canvas.Left="40" Canvas.Top="31" Width="63" Height="41" Fill="Blue"  />
    <Ellipse Canvas.Left="130" Canvas.Top="79" Width="58" Height="58" Fill="Blue"  />
    <Path Canvas.Left="61" Canvas.Top="28" Width="133" Height="98" Fill="Blue"
          Stretch="Fill" Data="M61,125 L193,28"/>
</Canvas>

 

 As found in most of the cases in my blogs, I prefer digesting the newly acquired knowledge, so take some time and explore the Architecture and Layout. The remaining topics would be covered in the upcoming Post.

Till Next we connect…….

Happy Learning!

 

Comments

Popular posts from this blog

Asp.Net 4.0: An Overview-Part-III

This is the last post in the series which will explore the following new features of ASP.Net 4.0  Performance Monitoring for Individual Applications in a Single Worker Process Web.config File Refactoring Permanently Redirecting a Page Expanding the Range of Allowable URLs Performance Monitoring for Individual Applications in a Single Worker Process It is a common practice to host multiple ASP.NET applications in a single worker process, In order to increase the number of Web sites that can be hosted on a single server. This practice results in difficulties for server administrators to identify an individual application that is experiencing problems. ASP.NET 4 introduces new resource-monitoring functionality introduced by the CLR. To enable this functionality, following XML configuration snippet is added to the aspnet.config configuration file.(This file is located in the directory where the .NET Framework is installed ) <?xml version="1.0" encoding="UTF-8...

Covariance and Contravariance-General Discussion

If you have just started the exploration of .Net Framework 4.0, two terms namely Covariance and Contravariance might have been heard. The concept that these terms encapsulate are used by most developer almost daily, however there has never been any botheration about the terminologies. Now, what actually these terms mean and how are these going to affect us as a developer, if we dive in to the details. The simple answer is it’s always good to know your tools before actually using them. Enough philosophy, let’s get to the business. Starting the discussion let me reiterate that in addition to Covariance and Contravariance, there is another terminology, Invariance. I’ll by start here by diving into the details of Invariance and then proceed further. Invariance: Invariance can be better understood by considering the types in .Net.>net has basically two type, value-types and reference-types. Value types (int, double etc) are invariant i.e. the types can’t be interchanged either ...

Advanced WCF

In this post, I am sharing the link of articles about  advanced topics in WCF. The List of articles is exhaustive and can serve as your repository for all WCF queries. Concurrency,Throttling & Callbacks  WCF Concurrency (Single, Multiple and Re entrant) and Throttling   WCF-Interop and BinarySecurityToken  WCF Callbacks  Creating Web Services From WSDL Link1 Link2 Link3 Link4 WCF-Security WCF over HTTPS   Transport Security(basic)/HTTPS UserNamePasswordValidator ServerCertificateValidationCallback 9 simple steps to enable X.509 certificates on WCF - CodeProject http://www.codeproject.com/KB/WCF/9StepsWCF.aspx?display=Print Message Security(Certificate)/PeerTrust Securing WCF Services with Certificates. - CodeProject http://www.codeproject.com/KB/WCF/wcf_certificates.aspx Message Security(Certificate)/ChainTrust How To Configure WCF Security Using Only X.509 Certificates - CodePr...