Top 50 Windows Presentation Foundation(WPF) Interview Questions You Must Prepare 02.Oct.2022

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

Commands are more powerful and are advantageous to use instead of events. Actions are deeply connected with the event 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.

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

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

One of the major differences is that .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.

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.

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.

The four general kind of XAML elements are:

  1. Root Elements
  2. Panel Elements
  3. Control Elements
  4. Geometric Elements

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

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.

WPF is the latest presentation API by Microsoft Windows. It is 2D and 3D graphic engine.

Its capabilities include:-

  • All the common user controls. For example, check boxes, buttons, sliders etc.
  • Supports flow and fix format documents
  • all the functionality of Flash and HTML
  • Data binding
  • Multimedia

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

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

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

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 (“).

For example,

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

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.

They are:

  • Stack Panel
  • Grid Panel
  • Canvas Panel
  • Dock Panel
  • Wrap Panel

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

Namespace can be defined as an environment or an abstract container used to hold a logical grouping of unique identifiers or symbols.

It has three objects, namely:

  • SetValue
  • ClearValue
  • GetValue

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

For example,
Tag with contents
Tag without contents
< Button/>

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

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

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.

The InotifyPropertyChanged notifies clients, generally those who are binding, if the value of a property gets changed. It has an event, called PropertyChanged, which gets raised everytime a property of Model object is changed.

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.

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

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

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.

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.

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

They are a special kind of FrameworkElement 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 UIElement and are rendered on a surface that lies above the element, which is adorned. This surface is called an AdornerLayer. Adorners are mostly placed relatively to the bounded element.

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.

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

For instance, this code sorts elements of ContentControl on the basis of their word count property:
myItemsControl.Items.SortDescriptions.Add(new SortDescription(“WordCount”, ListSortDirection.Descending));

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.

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

ListBox 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 ListBox lose the virtualization property.

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

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.

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

There are three types of Routed events in WPF.

They are:

  1. Direct – This event can only be raised by the element in which it was originated.
  2. 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.
  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.

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

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.

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

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

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

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.

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.

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=

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.

For this purpose, the ShowOnDisabled property can be used. It belongs to the ToolTipService class.