70+ WPF Interview Questions and Answers 2020

70+ WPF Interview Questions and Answers 2020

Here are WPF interview questions and answers below:

  1. What is WPF?

WPF is the latest presentation API from Microsoft Windows. It is a 2D and 3D graphic engine. Its capabilities include:-

  • All the common user controls. For example, buttons, checkboxes, sliders, etc.
  • All the functionality of Flash and HTML
  • Supports flow and fix format documents
  • Data binding
  • Animation
  • Multimedia
  1. What are the types of documents supported by WPF?

There are two types of documents supported by the Windows Presentation Foundation (WPF) are the Flow format and fixed Format document. Flow format document alters the content to fit the screen size while fixed-format document presents content irrespective of the screen size.

  1. Name the namespace required for working with 3D.

The namespace required for working in 3D is System.Windows.Media.Medi3D.

  1. 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.

  1. What are dependency properties?

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

  1. How can the size of the 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.

  1. 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.

  1. 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 robust control reuse.

  1. How is Silverlight different from the WPF browser application?

One of the major differences is that the .NET framework is required for running WPF browser applications on the client machine. But Silverlight runs using only the plug-in. Another point of difference is that applications made in WPF depend on the OS as .NET Framework only runs on Windows. On the other hand, the Silverlight plug-in can be installed on those OSs also, which are not Windows.

  1. Name the methods present in the Dependency Object.

It has three objects, namely:

  • ClearValue
  • SetValue
  • GetValue
  1. Write about PRISM.

PRISM is a framework for creating complex applications for WPF, Silverlight or Windows Phone. PRISM utilizes MVVM, IC, Command Patterns, DI and Separation of Concerns to get loose coupling.

  1. 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 WindowsFormsHost control that comes preinstalled.

  1. Describe Custom Control briefly.

Custom Control helps to 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 template.

  1. Name the common assemblies used in WPF?
  • Presentation Foundation
  • Windows Base
  • Presentation Core
  1. Define Path animations in WPF

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

  1. 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.

  1. What are the types of windows in WPF?

WPF has three types of windows:

  • Normal Window
  • Navigate Window
  • Page Window
  1. How can elements in a List Box be sorted?

Sorting can be done by using the property of the Items Collection object. Items Collection contains an attribute, Sort Descriptions, which holds the System. Component Model. Sort Description instances. Each word describes how to develop things and shows if it is coming or moving.

  1. How is MVVM different from MVC?

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

In MVVM, the View Model is used instead of a controller. This View Model is present beneath the UI layer. It explains what they are asked and what information you need. It works as a trunk box from which the viewpoint receives services and information.

  1. 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.

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

It is used whenever needed to create custom user design. 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.

  1. What are the various layout panels in WPF?

They are:

  • Grid Panel
  • Canvas Panel
  • Wrap Panel
  • Dock Panel
  • Stack Panel
  1. Name the important subsystems in WPF.

There are 7 major subsystems:

  1. DependancyObject
  2. FrameworkElement
  3. Object
  4. DispatcherObject
  5. Media.Visuals
  6. Controls.Control
  7. UIElements
  8. 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.

  1. What is the 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.

  1. What are Attached Properties in WPF?

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

  1. What is the INotifyPropertyChanged Interface?

The InotifyPropertyChanged 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.

  1. 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 the instructions make it possible to keep the correct settings in one place and then re-use them as we need.

  1. What is the method to force close a ToolTip, which is currently visible?

It can be closed by setting the tooltip’s open property to false.

  1. 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

  1. Explain MVVM pattern.

MVVM pattern divides the UI code into 3 basic parts:

  • View – It is the code that agrees with the visual representation of the data.
  • Model – It represents a set of classes, which contain data received from databases.
  • View Model – 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.
  1. Why is 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.

  1. 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 template.

  1. 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.

  1. 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.

  1. What is an adorner?

They are a special kind of Framework Element that provides 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 UIElement 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.

  1. Explain Serialization?

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

  1. Is MDI supported in WPF?

MDI is not supported in WPF. User Control can be used to give the same functionality as MDI.

  1. What is XBAP?

XBAP is the abbreviated form of XAML Browser Application. This 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, These applications can be created, which runs directly into the browser. These applications are called XBAP.

  1. In what sense are WPF and Silverlight similar?

Silverlight and WPF are similar in the sense that they both use XAML and share the same code, syntax and libraries.

  1. How to make a ToolTip appear while hovering over a disabled element?

For this purpose, the Show On Disabled property can be used. It belongs to the Tool Tip Service class.

  1. How can List Box be made to scroll smoothly?

List Box is configured to scroll on an item-by-item basis by default. This depends on the height of any part of the movement, so, not a bad feeling. The best way to adjust control measures is to change the content by some pixels regardless of the height. We did this by installing a Home Monitor. Can Content Scroll property to “false”. This will, however, make the List Box lose the virtualization property.

  1. 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.

  1. 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.

  1. What are the different kinds of Routed events in WPF?

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

  1. 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.
  2. Direct – This event can only be raised by the element in which it was originated.
  3. 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.
  4. Why is it better to wrap items in ComboBoxItem?

It has some important properties like Is Selected and Is Highlighted 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 ComboBox.

  1. 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 giving an ID to an element, other than its name, then the Automation Properties. Automation ID property can be set as per need.

  1. 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.

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

Content Control

  • Headed Content Control
  • Headed Items Control
  • Items Control
  1. Which Name Space has ‘Popup’ and ‘Thumb’ controls?

The namespace system.windows.controls.primitives has ‘Popup’ and ‘Thumb’ controls.

  1. Explain what is XAML?  What is the difference between XML and XAML?

XAML stands for extensible Application Markup Language. It is the language used to instantiate.NET objects.  This is a language developed by Microsoft incorporation to write user interface for next generation applications.

XML was designed to store data or to work with the stored data, whereas XAML is the extended version of XML used for.NET programming.

  1. Mention the advantage of using XAML?

The advantage of using XAML is

  • Separation of designer code and logic
  • XAML code is clear to read, and they are short
  • It clearly separates the roles of designer and developer
  • Tools like expression blend used for graphical design require XAML as source
  1. How can you code to display “Hello World” in XAML?

Displaying “Hello World.”

<page xmlns= ‘’ ‘’>
<TextBlock>
Hello, World!
</TextBlock>
</Page>
  1. In XAML how graphic components are specified?

In XAML, the graphic components are specified with by open or closed tags with attributes.

For example,

Tag with contents

<Button>

Click

</Button>

Tag without contents

< Button/>

  1. What is Attribute Syntax in XAML?

In XAML, attribute syntax sets a value for a property or names the event handler for an event, by declaring an attribute on an element.  The attribute value should be enclosed within two quotation marks (“).

Example,

< Button Background = “Black” Foreground “Red” Content = “This is an operating button”/>

XAML

  1. Explain Content Properties XAML?

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

  1. Explain what is Markup extension in XAML?

A markup extension is the placeholder in XAML that are used to resolve property at runtime. A markup extension allows user to extend XAML and using attribute syntax users 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 x: Array, xNull, Dynamic Resource and Static Resource.

  1. What are the four general kinds of XAML elements?

The four general kind of XAML elements are

  • Control Elements
  • Panel Elements
  • Geometric Elements
  • Root Elements
  1. What X: prefix indicates in XAML?

The X: prefix is used to map the XAML namespace in templates.

  1. What are the various X: prefix used in XAML language?
  • x: Class It specifies the CLR ( Common Language Runtime) namespace and class name for the class that provides code
  • X: Key sets a unique key for each resource in a Resource Dictionary
  • 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: Type à It constructs a Type reference based on the type name.
  • x: Static à It enables a reference that returns a static value which otherwise an XAML compatible property.
  1. How can you set a property attribute as a literal string and not a markup extension?

To avoid markup extension you have to use an empty pair of curly braces like

 

Content = “{} {This is not a markup extension}”/>

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

Three types of children an object element can have

  • Collection Items
  • The value that can be type-converted to the object element
  • A value for the content property.
  1. 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.

  • CanConvertFrom
  • ConvertFrom
  • ConvertTo
  • CanConvertTo
  1. 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.

  1. What are the ways you can declare objects in XAML?
  • Directly, using object element syntax: This syntax is used to declare root objects or nested objects that set property values
  • To declare objects in XAML, there are three ways
  • Indirectly by using attribute syntax: This syntax uses an inline string value which has an instruction on how to create an object. To set the value of the property to a newly created reference, the XAML parser uses this string
  • Using a markup extension.
  1. What should a root element of an XAML document contain?

In XAML documents, the root element consists of only certain elements, and these elements are Window, a Canvas or panels.

  1. What is data binding with XAML?

The Data binding provides a simple way to display and interact with data. An example will show how you can do data binding in XAML. Binding in XAML is done by using {binding….} syntax.

  1. Explain how you can display different data at run time and design time?
  • One way of displaying data at run time and design time is to declare your data in XAML.
  • Another way of doing it is by declaring it in XAML by using various data attributes from the designer XML namespace. With a d: prefix, this namespace is typically declared.

xmlns: d= http://schemas.microsoft.com/expression/blend/2008

  1. Explain what the function is x: Key directive in XAML?

X: Key uniquely identifies elements that are created and referenced in an XAML defined dictionary. By adding an x: Key value to an XAML object element a resource in the resource dictionary can be identified and is the most common way to identify.

  1. Explain what is the use of property element syntax?

With the help of property element syntax, user can add children element with a name in the form of parent.propertyName.

  1. How custom classes used in XAML can be defined?

Custom classes are used in two ways

  • In a separate assembly as a class, such as an executable or DLL used as a class library.
  • With the code that produces the Primary Windows Presentation Foundation (WPF) application or within the code behind.
  1. What is Xaml Namespace?

Namespace is said to be an environment or an abstract container used to hold a logical grouping of unique identifiers or a symbol.

Leave a Reply

Close Menu