WPF Interview Questions Part 3

Explain WPF styles ?

WPF styles work just like CSS style, In the CSS we define styles for a control and we reuse the same where ever we need in the application, same way the styles in WPF allows to define the properties and can be reused in the application.

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.

What is Command Design Pattern in WPF?

Command Design Pattern is one of the most powerful design patterns in object oriented design patterns. This pattern allows you to decouple the request of an action from the object that actually performs an action, in other words a command pattern represents an action as an object. A Command object does not contain the functionality that is to be executed. This removes the direct link between the command definitions and the functionality and it’s promoting a loose coupling. When you want to implement operations based on the user request then the command pattern is the best pattern to handle your object.

The following are the members of the Command Design Pattern:

Concrete Command

WPF Interview Questions

What is the need of WPF when we had windows forms?

Remember: – ABCDEFG

A – Anywhere execution ( Windows or Web)
B – Bindings ( less coding)
C – Common look and feel ( resource and styles)
D – Declarative programming (XAML)
E – Expression blend animation ( Animation ease)
F – Fast execution ( Hardware acceleration)
G – Graphic hardware independent ( resolution independent)

What is xmlns in XAML file ?

“xmlns” stands for XML namespaces. It helps us to avoid name conflicts and confusion in XML documents.

When should we use “x:name” vs “name” ?

There is no difference between “x:name” and “name” , “name” is short hand of “x:name”. But in classes where you do not find “name” property (this is a rare situations) we need to use “x:name” property.

Advance WPF Interview Questions

Can you explain the complete WPF object hierarchy?

Object: As WPF is created using .NET so the first class from which WPF UI classes inherits is the .NET object class.
Dispatcher: This class ensures that all WPF UI objects can be accessed directly only by the thread who own him. Other threads who do not own him have to go via the dispatcher object.
Dependency: WPF UI elements are represented by using XAML which is XML format. At any given moment of time a WPF element is surrounded by other WPF elements and the surrounded elements can influence this element and this is possible because of this dependency class. For example if a textbox surrounded by a panel, its very much possible that the panel background color can be inherited by the textbox.
Visual: This is the class which helps WPF UI to have their visual representation.
UI Element: This class helps to implement features like events, input, lay outing etc.
Framework element: This class supports for templating , styles , binding , resources etc.
And finally all WPF controls textbox , button , grids and whatever you can think about from the WPF tool box inherits from the framework element class.

Can you explain the overall architecture of WPF?

User32: It decides which goes where on the screen.
DirectX: As said previously WPF uses DirectX internally. DirectX talks with drivers and renders the content.
Milcore: Mil stands for media integration library. This section is a unmanaged code because it acts like a bridge between WPF managed and DirectX / User32 unmanaged API.
Presentation core : This is a low level API exposed by WPF providing features for 2D , 3D , geometry etc.
Presentation framework: This section has high level features like application controls , layouts . Content etc which helps you to build up your application.

Could you tell me what is the main differences between Style and Control Template?

Styles set properties on controls.
Control Template is a property shared by most controls that specify how they are rendered.
To elaborate, you can use a style to group settings for a bunch of properties so you can re-use that to standardize your controls. Styles can be set explicitly on controls or applied too all of a certain type.

Control Templates can be set by a style or set explicitly on a control to change the way it appears. All controls have default templates (and styles for that matter) that are embedded in the .NET wpf assemblies.

WPF Interview Questions

Does WPF build on top of Windows Forms or are they totally different?

These two are totally different technologies. They do offer some interoperability layers to both directions, but other than that have nothing in common. Windows Forms is more or less a lightweight wrapper on top of Win32/MFC, which means its extensibility in .NET is not that good in all cases. WPF is a new UI framework implemented from scratch. WPF is also much more flexible when it comes to customizing the existing types.

WPF is better for cross platform development and creating ‘flashy’ GUI’s. However it requires a newer .net framework than WinForms and requires a dx9 compatible GPU or higher (which most people will have).

WinForms is still a powerful technology which can often be developed at a faster pace than WPF however, in the end, both technologies can be used to achieve the same thing. WinForms is commonly used to develop business applications whereas WPF is often used to create more end-user based bits of software, apps etc.

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 an optimum solution to make games, oh yes you can make a TIC TAC TOE game but not high action animation.

One point to remember WPF is a replacement for windows form and not DirectX.

In WPF, what are the differences between the x:Name and Name attributes?

They are not the same thing.

x:Name is a xaml concept, used mainly to reference elements. When you give an element the x:Name xaml attribute, “the specified x:Name becomes the name of a field that is created in the underlying code when xaml is processed, and that field holds a reference to the object.” (MSDN) So, it’s a designer-generated field, which has internal access by default.
Name is the existing string property of a FrameworkElement, listed as any other wpf element property in the form of a xaml attribute.
As a consequence, this also means x:Name can be used on a wider range of objects. This is a technique to enable anything in xaml to be referenced by a given name.

Advance WPF Interview Questions

List Box vs. List View – what and when to choose for data binding?

A List View is a specialized List Box (that is, it inherits from List Box). It allows you to specify different views rather than a straight list. You can either roll your own view, or use Grid View (think explorer-like “details view”). It’s basically the multi-column list box, the cousin of windows form’s list view.

If you don’t need the additional capabilities of List View, you can certainly use List Box if you’re simply showing a list of items (Even if the template is complex).

Name some advantages of using Windows Forms instead of WPF

Top advantages of using Windows forms instead of WPF:

WPF’s in-box control suite is far more limited than that of WinForms.
There’s greater support in the 3rd-party control space for WinForms. (That’s changing, but for now by advantage of time, WinForms has greater support in the community.)
The major drawback of WPF is that Mono doesn’t really support it for cross-platform (e.g., it doesn’t work on Linux and Mac). Originally, Xamarian/Novella said they weren’t going to implement it due to the complexity of implementation. I haven’t seen anything to the contrary. Not saying it isn’t, but their recommendation is to write model classes and then do a OS-specific front end. Even with WPF being open sourced, it may be built on something that isn’t easily ported.

What is Freezable Object?

A Freezable is a special type of object that has two states: unfrozen and frozen. When unfrozen, a Freezable appears to behave like any other object. When frozen, a Freezable can no longer be modified.

A Freezable provides a changed event to notify observers of any modifications to the object. Freezing a Freezable can improve its performance, because it no longer needs to spend resources on change notifications. A frozen Freezable can also be shared across threads, while an unfrozen Freezable cannot.

Although the Freezable class has many applications, most Freezable objects in Windows Presentation Foundation (WPF) are related to the graphics sub-system.

WPF Interview Questions

What is the difference between Visual and Logical Tree in WPF?

Elements of a WPF user interface are hierarchically related. This relation is called the Logical Tree. The template of one element consists of multiple visual elements. This tree is called the Visual Tree.

The logical tree describes the relations between elements of the user interface. The logical tree is responsible for:

Inherit Dependency Property values
Resolving Dynamic Resources references
Looking up element names for bindings
Forwarding Routed Events
The visual tree contains all logical elements including all visual elements of the template of each element. The visual tree is responsible for:

Rendering visual elements
Propagate element opacity
Propagate Layout- and Render Transforms
Propagate the IsEnabled property.
Do Hit-Testing
Relative Source (Find Ancestor)

What is the difference between a Page and a Window in WPF when you are adding a new file in the Solution Explorer?

Pages are intended for use in Navigation applications (usually with Back and Forward buttons, e.g. Internet Explorer). Pages must be hosted in a Navigation Window or a Frame.
Windows are just normal WPF application Windows, but can host Pages via a Frame container.

What is the use of a Dispatcher Object in WPF?

Almost every WPF element has thread affinity. This means that access to such an element should be made only from the thread that created the element. In order to do so, every element that requires thread affinity is derived, eventually, from Dispatcher Object class. This class provides a property named Dispatcher that returns the Dispatcher object associated with the WPF element.

The Dispatcher class is used to perform work on his attached thread. It has a queue of work items and it is in charge of executing the work items on the dispatcher thread.

Advance WPF Interview Questions

What is CLR?

CLR stands for Common Language Runtime. It is a run time environment for .NET

What are the freezable objects in WPF?

An object which is unchangeable is known as freezable object. The freezable objects perform better and also safer if they are required to be shared between threads.

What is Custom Control?

Custom Control is used to expand the functions of existing controls. It contains a default style in theme and code file

WPF Interview Questions

What is the use of custom control?

Custom control is the best way to make a control library. It can also be styled or template.

What is the Path animation in WPF?

Path animation is a different type of animation. In this animation, the animated objects follow a path set by the path geometry.

What is the meaning of BAML in WPF?

BAML stands for Binary Application Markup Language. It is a type of XAML that has been tokenized, parsed, and changed into binary form.

Advance WPF Interview Questions

What is the parent class of control class of WPF?

The control class of WPF is derived from Framework Element.

Is MDI supported in WPF?

MDI is not supported in WPF. The same functionality of MDI can be given by User Control.

What is serialization?

Serialization is a process of converting the state of an object to stream of bytes.

WPF Interview Questions

What are the most important features of MVVM?

A list of most important features of MVVM:

MVVM separates the business and presentation layers, like MVP and MVC.
It improves Structure/separation of concerns (View, ViewModel and Model).
It enables a better Design/Developer Workflow.
It improves simplicity and testability.
It is enabled by the robust data binding capability of XAML.
No need to use a code behind file (minimalist code-behind file).
Provides application development ability for multiple environments.
Powerful Data Binding, command, validation and much more.
The designer and developer can work together.

When did MVVM introduced?

MVVM was introduced by John Gossman in 2005. It was introduced specifically to use with WPF as a concrete application of Martin Fowler’s broader Presentation Model pattern.

What is the value converter in WPF?

A Value Converter is known to function as a bridge between a source and a target that is necessary when a target is bound with one source, for example, if you have a text box then you also has a button control. You want to disable or enable or disable the button control when the text of the text box is null or filled.

Sometimes the string data needs to be converted into Boolean. This is only possible when using a Value Converter. For implementing Value Converters, it requires you to inherit from I Value Converter in the System.Windows.Data namespace and then implement the two methods Convert Back and Convert.

You may note that in WPF, binding helps in the flow of data between the two WPF objects. The bound object that emits the data is called the Source, and the other (that accepts the data) is called the Target.

WPF Interview Questions

What can you do in Expression Blend that you cannot do in Visual Studio?

To blend expression in a Visual Studio

Configure visual states
Configure brushes and gradient brushes in the properties window
Configure object timelines
Configure sample data
And many other design features

List some common Localization or Globalization practices for Localizing or Globalizing WPF?

Some common localization or globalization practices for localizing or globalizing WPF are:

1) Use Resources.resx,

2) Use BAML,

3) Use a Resource Dictionary to manage localizable strings.

What do you understand by a Routed event and what are its types?

A Routed Events is all about the Hierarchy of the controls that are used by us in the Events. Routed Events are known to be a new Infrastructure that is given by WPF that permits events to go tunneling down the tree to the target elements or Bubble up to the Root element. Events are simply like normal events. Types of routed events

Basically Routed Events are of mainly three types that are as follows:

Tunneling Events
Bubbling Events
Direct Events

Advance WPF Interview Questions

In WPF, what do you understand by Rotate transform?

As the name suggests, Rotate transform rotates the element, by a specific angle clockwise about a point. The rotate transform is represented by the Rotate Transform object in WPF. The angle in degrees to be rotated clockwise is known as Angle property of Rotate Transform. The center Y and CenterX represent the Y and X coordinates of the center point. The Scale Transform is centered at the point (0,0) that corresponds to the upper-left corner of the rectangle, which is by default in nature.

How to bind xml in wpf?

XmlDataProvider provides the flexibility to bind XML object to target properties.

Difference between DataContext and ObjectDataProvider ?

Data context is used for an already created instance. It searched the property of the existing instance and binds to the target property. ObjectDataProvider creates an instance in Xaml and binds the property.

WPF Interview Questions

List some of the best practices of using WPF in case you are planning to build a Localized/Globalized application?

If you are planning to build a localized or globalized application.

You can write UI in XAML
Avoid positioning and sizing but lets the objects flow automatically
Enables text wrapping

What do you understand by Virtualization in WPF?

To improve the rendering performance of UI elements the Virtualization technique in WPF is used. By using Virtualization technique the layout system ensures that the only items visible of a container are rendered on the screen. Like for instance, if a list control has thousands of items, the virtualization technique will reduce the rendering to just visible items.

WPF Part 1WPF Part 2
Back to top