Tuesday, December 27, 2011

WPF



What is WPF?
Windows Presentation Foundation (Avalon was the code name for WPF) is the new presentation API in WinFX. WPF is a two and three dimensional graphics engine. It has the following capabilities:-
• Has all equivalent common user controls like buttons, check boxes sliders etc.
• Fixed and flow format documents
• Has all of the capabilities of HTML and Flash
• 2D and 3D vector graphics
• Animation
• Multimedia
• Data binding
What is XAML?
XAML (pronounced as Zammel) is a declarative XML-based language by which you can define object and properties in XML. XAML document is loaded by a XAML parser. XAML parser instantiates objects and set there properties. XAML describes objects, properties and there relation in between them. Using XAML, you can create any kind of objects that means graphical or non-graphical. WPF parses the XAML document and instantiates the objects and creates the relation as defined by XAML.
So XAML is a XML document which defines objects and properties and WPF loads this document in actual memory.
Does that mean WPF has replaced DirectX?
No, WPF does not replace DirectX. DirectX will still be still needed to make cutting edge games. The video performance of directX is still many times higher than WPF API. So when it comes to game development the preference will be always DirectX and not WPF. WPF is not a optimum solution to make games, oh yes you can make a TIC TAC TOE game but not high action animation games.

One point to remember WPF is a replacement for windows form and not directX. 
So can we define WPF in a precise way?
Windows Presentation Framework is the new presentation API. WPF is a two and three dimensional graphics engine. It has the following capabilities:-
• Has all equivalent common user controls like buttons, check boxes sliders etc.
• Fixed and flow format documents
• Has all of the capabilities of HTML and Flash
• 2D and 3D vector graphics
• Animation
• Multimedia
• Data binding
What is XAML?
XAML (pronounced as Zammel) is a declarative XML-based language by which you can define object and properties in XML. XAML document is loaded by a XAML parser. XAML parser instantiates objects and set their properties. XAML describes objects, properties and there relation in between them. Using XAML, you can create any kind of objects that means graphical or non-graphical. WPF parses the XAML document and instantiates the objects and creates the relation as defined by XAML.
So XAML is a XML document which defines objects and properties and WPF loads this document in actual memory.
  
 
So is XAML meant only for WPF?
No,XAML is not meant only for WPF.XAML is a XML-based language and it had various variants.
WPF XAML is used to describe WPF content, such as WPF objects, controls and documents. In WPF XAML we also have XPS XAML which defines an XML representation of electronic documents.
Silverlight XAML is a subset of WPF XAML meant for Silverlight applications. Silverlight is a cross-platform browser plug-in which helps us to create rich web content with 2-dimensional graphics, animation, and audio and video.
WWF XAML helps us to describe Windows Workflow Foundation content. WWF engine then uses this XAML and invokes workflow accordingly
There are ten important namespaces / classes in WPF.

System.Threading.DispatcherObject

All WPF objects derive from the DispatcherObject. WPF works on STA model i.e. Single Threading Apartment Model. The main duty of this object is to handle concurrency and threading. When any message like mouse clicks, button clicks etc are initiated they are sent to the DispatcherObject who verifies whether code is running on the correct thread. In the coming section we will look in to detail how WPF threading works.
System.Windows.DependencyObject
When WPF was designed property based architecture was considered. In other words rather than using methods, functions and events object behavior will interact using properties. For now we will only restrict ourselves to this definition. In the coming section we have dedicated question for the same.
 System.Windows.Media.Visual

Visual class is a drawing object which abstracts drawing instructions, how drawing should be drawn like clipping, opacity and other functionalities. Visual class also acts like a bridge between unmanaged MilCore.dll and WPF managed classes. When any class derived from visual it can be displayed on windows. If you want to create your own customized user interface then you can program using visual objects.
 
System.Windows.UIElement

UIElement handled three important aspects layout, input and events.
System.Windows.FrameworkElement
FrameWorkElement uses the foundation set by UIElement. It adds key properties like HorizontalAlignment , VerticalAlignment , margins etc.

System.Windows.Shapes.Shape

This class helps us to create basic shapes such as Rectangle, Polygon, Ellipse, Line, and Path.

System.Windows.Controls.Control

This class has controls like TextBox,Button,ListBox etc. It adds some extra properties like font,foreground and background colors.

System.Windows.Controls.ContentControl

It holds a single piece of content. This can start from a simple label and go down to a unit level of string in a layout panel using shapes.
System.Windows.Controls.ItemsControl
This is the base class for all controls that show a collection of items, such as the ListBox and TreeView.

System.Windows.Controls.Panel

This class is used for all layout containers—elements that can contain one or more children and arrange them as per specific layout rules. These containers are the foundation of the WPF layout system, and using them is the key to arranging your content in the most attractive, flexible way possible.
  
  
Q1. What is WPF?
WPF stands for Windows Presentation Foundation. It is an application programming Interface for developing rich UI on Windows. WPF is introduced in .NET 3.0. By the use of WPF we can create two and three dimensional graphics,animations etc.

Q2. What is XAML and how it is related to WPF?
XAML is a new mark up language which is used for defining UI elements and its relationships with other UI elements. The XAML is introduced by WPF in .NET 3.0 WPF uses XAML for UI design.

Q3. Does XAML file compiled or Parsed?
By default XAML files are compiled ,But we do have options to let it be parsed.

Q4. What is the root namespace used for Animations and 3D rendering in WPF?
System.Windows.Media namespace.

Q5. What are the names of main asseblies used by WPF?
a)WindowsBase
b)PresentationCore
c)PresentationFoundation

Q6. What operating systems support WPF?
Following are the operating systems that support WPF
a)Windows7
b)Windows Vista
c)Windows XP Service Pack 2 or later

Q7. Describe the types of documents supported by WPF?
There are two kinds of document supported by WPF
a)Flow format:Flow format document adjusts as per screen size and resolution
b)Fixed Format:Fixed Format document does not adjust as per screen size and resolution

Q8. What namespaces are needed to host a WPF control in Windows form application?
The following namespaces needs to be referenced :
a)PresentationCore.dll
b)PresentationFramework.dll
c)UIAutomationProvider.dll
d)UIAutomationTypes.dll
e)WindowsBase.dll
 
Q9. What is Dependency Property In WPF?
Windows Presentation Foundation (WPF) has a set of services that is used to extend the functionality of a common language runtime property. These services are referred as the WPF property system. A property that is backed by the WPF property system is known as a dependency property 
Q10.What is routed event in WPF?
A WPF user interface is constructed in a layered approach, where one visual element can have zero or more child elements. so we can visualise the elements tree for the full page. Routed events are a new feature provided by WPF which allows events to travel down the elements tree to the target element, or bubble up the elements tree to the root element. When an event is raised, it "travels" up or down the elements tree invoking handlers for that event on any element subscribed to that event it encounters en route.This tree traversal does not cover the entire elements tree, only the ancestral element chain between the root element and the element which is the target of the event.

Name the Layut Panels of WPF?

These are the five most layout panels of WPF:-
1)Grid Panel
2)Stack Panel
3)Dock Panel
4)Wrap Panel
5)Canvas Panel

What are the difference between CustomControls and UserControls in WPF?

CustomControl (Extending an existing control):-
----------------------------------------------
1)Extends an existing control with additional features.
2)Consists of a code file and a default style in Themes/Generic.xaml.
3)Can be styled/templated.
4)The best approach to build a control library.

UserControl (Composition):-
--------------------------
1)Composes multiple existing controls into a reusable "group".
2)Consists of a XAML and a code behind file.
3)Cannot be styled/templated.
4)Derives from UserControl.

What are the Advantages of XAML?

1)XAML code is short and clear to read.
2)Separation of designer code and logic.
3)Graphical design tools like Expression Blend require XAML as source.
4)The separation of XAML and UI logic allows it to clearly separate the roles of designer and developer.

No comments: