WPF Interview Questions Part 2

Is it right to say that WPF has replaced DirectX?

No, WPF can never replace DirectX. WPF cannot be used to create games with stunning graphics. WPF is meant to be a replacement for windows form, not DirectX.

What are dependency properties?

Properties that belong to a specific class but can be used for another are called the dependency properties.

How can the size of Status Bar be increased proportionally?

By overruling the Items Panel attribute of Status Bar with a grid. The grid’s columns can be appropriately configured to get the desired result.

WPF Interview Questions

What are Freezable objects in WPF?

An object, which has its state locked down, so that it becomes unchangeable, is known as a freezable object. Such objects perform better. It is also safer if they are required to be shared between threads.

Why should WPF be preferred over Adobe Flash?

WPF is a more recent technology and thus has the latest development tools. It supports a broader range of programming languages and has a robust control reuse.

Name the methods present in the Dependency Object.

It has three objects, namely:

Set Value
Clear Value
Get Value

Advance WPF Interview Questions

Is it possible to use Windows Forms in a WPF application?

Yes, Windows form can be used in WPF. Windows form can appear as a WPF pop. The controls of this Window form can be placed besides WPF controls in a WPF page by utilizing the functions of the Windows Forms Host control that comes preinstalled.

Describe Custom Control briefly.

Custom Control widens the functions of existing controls. It consists of a default style in Themes/Generic.xaml and a code file. It is the best way to make a control library and can also be styled or templated.

Name the common assemblies used in WPF?

Presentation Foundation
Windows Base
Presentation Core

WPF Interview Questions

Define Path animations in WPF

Path animation is a type of animation in which the animated object follows a path set by the Path geometry.

Can WPF applications be made without XAML?

Yes WPF applications can be created without XAML as using XAML in WPF is a matter of choice.

How can elements in a List Box be sorted?

Sorting can be done by using a property of the Items Collection object. Items Collection contains an attribute, Sort Descriptions, which holds System.ComponentModel.SortDescription instances. Every Sort Description instance defines how the elements should be sorted and indicates if the sort is descending or ascending.

For instance, this code sorts elements of Content Control on the basis of their word count property:

myItemsControl.Items.SortDescriptions.Add(new SortDescription(“WordCount”, ListSortDirection.Descending));

Advance WPF Interview Questions

How is MVVM different from MVC?

MVC stands for Model-View Controller and. MVVM stands for Model-View ViewModel.

In MVVM, View Model is used instead of a controller. This View Model is present beneath the UI layer. It reveals the command objects and data that the view requires. It acts like a container object from which view gets its actions and data.

Explain Routed events in WPF.

An event, which can invoke handlers on more than one listeners present in an element tree, instead of the single object which called the event, is known as a Routed event.

How is System.Windows.Media.Visual dll utilized in WPF?

It is used whenever a requirement for creating custom user interface arises. It is a drawing object, which gives instructions for making an object. These instructions include opacity etc. of the drawing. The Visual class also bridges the functionalities of WPF managed classes and the MilCore.dll.

WPF Interview Questions

What are the various layout panels in WPF?

They are:

Stack Panel
Grid Panel
Canvas Panel
Dock Panel
Wrap Panel

Name the important subsystems in WPF

The major subsystems are:


What does BAML mean in WPF?

BAML is the abbreviation for Binary Application Markup Language. It is nothing but XAML that has been tokenized, parsed and changed into binary form. BAML is a compressed declarative language, which gets loaded and parsed quicker than XAML.

Advance WPF Interview Questions

What is Difference between Page and Window Controls in WPF?

The basic difference is that Window Control presides over Windows Application while Page Control presides over the hosted Browser Applications. Also, Window control may contain Page Control, but the reverse cannot happen.

What are Attached Properties in WPF?

Attached properties are basically Dependency Properties that allows the attachment of a value to any random object.

What is the INotifyPropertyChanged Interface?

The Inotify Property Changed notifies clients, generally those who are binding, if the value of a property gets changed. It has an event, called Property Changed, which gets raised every time a property of Model object is changed.

WPF Interview Questions

What is the basic difference between Events and Commands in the MVVM Model?

Commands are more powerful and are advantageous to use instead of events. Actions are deeply connected with the event’s source and, therefore, the events cannot be reused easily. But commands make it possible to efficiently maintain multiple actions at one place and then reuse them as per our requirement.

Write the differences between Dynamic Resource and Static Resource.

The most basic difference is that Static Resource evaluates the resource one time only, but Dynamic Resource evaluates it every time the resource is required. And due to this reason, Dynamic Resource is heavy on the system but it makes pages or windows load faster

Explain MVVM pattern.

MVVM pattern divides the UI code into 3 basic parts:

Model – It represents a set of classes, which contain data received from databases.
View – It is the code that agrees with the visual representation of the data.
ViewModel – It is the layer that binds View and Model together. It presents this data in a manner, which is easy to understand. It also controls how View interacts with the application.

Advance WPF Interview Questions

Why are layout panels needed for in WPF?

Layout Panels are needed so that the controls fit screens of different sizes or having different font sizes. If we arrange controls on fixed pixel coordinates, then this model will fail when moved to a different environment. For this reason, Layout panels are necessary.

Write about User Control in brief.

User Control wraps existing controls into a single reusable group. It contains a XAML file and a code. User Control cannot be styled or templated.

What is the way to determine if a Freezable object is Frozen?

“Is Frozen” property of the object can be used to determine if the freezable object is frozen.

WPF Interview Questions

What is the unit of measurement in WPF?

All measurements are made in device-independent pixels, or logical pixels. One pixel is 1/96th part of an inch. These logical pixels are always mentioned as double, this enables them to have a fractional value too.

What is an adorner?

They are a special kind of Framework Element that provide visual clues to the user. They are also used to add handles to elements and give information about the state of a control. Adorners are bound to the UI Element and are rendered on a surface that lies above the element, which is adorned. This surface is called an Adorner Layer. Adorners are mostly placed relatively to the bounded element.

What is XBAP?

XBAP is the abbreviated form of XAML Browser Application. It allows WPF applications to run inside web browsers. Installation of .NET framework on the client machine is a prerequisite for running WPF applications. But hosted applications are not given full admission to the client’s machine and are executed in a sandbox environment. Using WPF, such applications can also be created, which run directly in the browser. These applications are called XBAP.

Advance WPF Interview Questions

How can List Box be made to scroll smoothly?

List Box is configured to scroll on an item-by-item basis by default. This is dependent on the height of each element and the scrolling action, thus, giving a rough feeling. Better way is to configure scrolling action so that it shifts items by a few pixels irrespective of their height. This is done by setting the ScrollViewer.CanContentScroll property to “false”. This will, however, make the List Box lose the virtualization property.

Where does the execution start in a WPF application?

WPF applications created in Visual Studio run without a Main method. This is because the applications are special-cased when they are compiled from XAML. That means, Visual Studio attaches a Build Action of Application Definition to the XAML file. This results in the auto generation of a Main method.

Can Windows Service be created Using WPF?

No, Windows Services cannot be created using WPF. WPF is a presentation language. Windows services need specific permissions to execute some GUI related functions. Therefore, if it does not get the required permissions, it gives errors.

WPF Interview Questions

What are the different kinds of Routed events in WPF?

There are three types of Routed events in WPF. They are:

Direct – This event can only be raised by the element in which it was originated.
Tunneling – This event is first raised by the element in which it was originated and then it gets raised by each consecutive container in the visual tree.
Bubbling – This event is first raised by the uppermost container in the visual tree and then gets raised by each consecutive container lying below the uppermost one, till it reaches the element it where it was originated.

Why is it better to wrap items in ComboBoxItem?

It has some important properties like IsSelected and IsHighlighted and also some necessary events like Selected and Unselected. ComboBoxItem is a content control and is thus very useful for adding simple strings to a Combo Box.

How to get Automation IDs of items in a Items Control?

The best way to do this is by setting it Name property as it is utilized for automation purposes by default. But if you require to give an ID to an element, other than it’s name, then the AutomationProperties.AutomationID property can be set as per need.

Advance WPF Interview Questions

How can command-line arguments be retrieved in a WPF application?

The most preferred method for this is to call System.Environment.GetCommandLineArgs at any random point in the application.

State the name of the classes, which contain arbitrary content.

Content Control

HeaderedContent Control

Items Control

HeaderedItems Control

Mention the advantage of using XAML?

The advantage of using XAML is

XAML code is clear to read, and they are short
Separation of designer code and logic
Tools like expression blend used for graphical design require XAML as source
It clearly separates the roles of designer and developer

WPF Interview Questions

Explain Content Properties XAML?

XAML represents a language feature whereby a class can allot exactly one of its properties as XAML property

Explain what is Markup extension in XAML?

Markup extensions are placeholders in XAML that are used to resolve property at runtime. A markup extension allows you to extend XAML and using attribute syntax you can also set any property that can be set in XAML. The purpose of the mark up extension is to process a string and return an object. Some of the standard markup extensions are xNull, x: Array, :StaticResource and DynamicResource.

What are the four general kinds of XAML elements?

The four general kind of XAML elements are

Root Elements
Panel Elements
Control Elements
Geometric Elements

Advance WPF Interview Questions

What are the various X: prefix used in XAML language?

x: Key à It sets a unique key for each resource in a Resource Dictionary
x: Classà It specifies the CLR ( Common Language Runtime) namespace and class name for the class that provides code
x: Name à It specifies a run-time object name for the instance that exist in run time code after an object element is processed
x: Static à It enables a reference that returns a static value which otherwise an XAML compatible property
x: Type à It constructs a Type reference based on the type name

What are the types of children does object element can have in XAML?

Three types of children an object element can have

Collection Items
A value for the content property
The value that can be type-converted to the object element

Explain what is Type Converter?

The type converter is helpful to convert a string into the appropriate value type where there is no markup extension usage. Type Converter defines four members for converting to and from string for xaml purposes.

Can Convert To

WPF Interview Questions

Explain Object Element Syntax in XAML?

To instantiate a CLR class or structure by declaring an XML element, an XAML markup syntax is used. This syntax is referred as Object Element Syntax.

WPF Part 1WPF Part 3
Back to top