Register Login

WPF Interview Questions and Answers

Updated Aug 12, 2019

What is WPF?

Windows Presentation Foundation or WPF is an engine developed by Microsoft using a GUI framework along with the .NET framework. It is used to create, display, and manipulate user-interfaces, images, documents, movies, and media in Windows operating systems.

In other words, WPF is a collection of libraries that have all the tools required to build, execute, and manage Windows client applications.

What are some characteristics of WPF?

The important characteristics of WPF are-

  • WPF Application uses the DirectX components and therefore is independent of the type or resolution of the screen.
  • User Interface and appearance in WPF application are independent of the functionality of the application, which is handled by .NET languages such as C#/VB.Net, etc.
  • In WPF, it is possible to add control within another control, unlike any other similar application.
  • Declarative programming in WPF allows the developers to define a thick client UI.
  • In WPF, developers can declare the template of the controls.

Explains Architecture of WPF?

WPF has a multi-layered architecture with three main layers-

  • WPF Managed Layer
  • WPF Unmanaged Layer
  • Core operating system element.

WPF Architecture

These layers are composed of assemblies that make up the entire framework.

1) Managed Layer

Managed layer consist of:

  • PresentationFramework.dll,
  • PresentationCore.dll, and
  • WindowsBase.dll.

2) Unmanaged layer

Unmanaged layer consists of:

  • milCore.dll 
  • WindowsCodecs.dll.

3) Core

Core operating system element consists of

  • DirectX,
  • User32
  • GDI (Graphic Device Interface)
  • CLR (Common Language Runtime)
  • Device Driver 

What are different in-built WPF layout panels?

The different types of in-built layout panels are:

  • Grid
  • Canvas
  • DockPanel
  • StackPanel
  • WrapPanel
  • UniformGrid

Mentions some important WPF assemblies?

The important WPF assemblies are-

  • Dispatcher Object
  • Dependency Property
  • Dependency Object
  • Dispatcher Timer

What is Dependency Property in WPF?

Dependency Properties are the basis for many key WPF features like data binding, styles, animation etc. Dependency property work as a conjunction of CLR property to take advantage of specific functions in the WPF, such as data binding.

What is XAML in WPF?

XAML is Microsoft’s descriptive programming language that is helpful in writing user interfaces in next-generation managed applications.

What is a dispatcher in WPF?

All UI thread queues methods in WPF calls inside a WPF Dispatcher object that affects all the changes on the screen. Dispatcher allows the execution of message queues into asynchronous order.

How to connect database in WPF application?

Connection to the database can be established using the following syntax-

SqlConnection dbconnect= new SqlConnection

 {   ConnectionString=ConfigurationManager.ConnectionStrings["Db_Connection_String"].ConnectionString

 };

 dbconnect.Open();

 SqlCommand sqlcmd = new SqlCommand("Query to execute");

 sqlcmd .ExecuteNonQuery();

 dbconnect.Close();

 What are the triggers in WPF?

A Trigger in WPF is used in Style or ControlTemplate to trigger on properties of something to show a "hot" effect. There are five triggers in WPF, namely-

  • Property Trigger
  • Data Trigger
  • MultiTrigger
  • MultiDataTrigger
  • Event Trigger

Difference WCF and WPF?

The main difference between WCF and WPF is in the use of the two. While Windows Communication Foundation builds service-oriented applications, Windows Presentation Foundation writes platform-independent applications. WCF connects to different applications and passes the data between them. WPF, on the other hand, designs rich internet applications in XAML format.

How many types of templates in WPF?

There are different types of templates in WPF are:

  • Control Template
  • Data Template
  • ItemsPanel Template
  • HierarchalData Template

What is Dock panel in WPF?

Dockpanel in WPF refers to the area where relative child elements arranged either horizontally or vertically. Child elements can be docked at the top, bottom, left, right and center according to their Dock property of the respective child element.

What is the base object in WPF?

A base object in WPF is class that allows other windows to inherit components from WPF.

What is a visual tree and logical tree in WPF?

Logical Tree is a tree structure which represents the hierarchy of essential structure of User Interface in WPF. It doesn't represent inner structure of the tree.

Visual tree is a tree structure which represents all of the element in our UI which are visible on the screen.

What is MVVM?

MVVM stands for Model-View-ViewModel (MVVM) pattern. In this, the View Model beneath the UI layer replaces the controller. It also displays the data and command objects essential for the view to perform actions.

How to create a custom control in WPF?

The steps to create custom controls in WPF are:

  • In a new WPF project, select Add by right-clicking on the solution.
  • Click on New Item.
  • Choose Custom Control (WPF) and assign a name to it.
  • Click the Add button to add Themes/Generic.xaml and MyCustomControl.cs to the solution.
  • Compile and execute the C# code or XAML code to generate the custom control.

Explain different types of Command used in WPF?

The various types of commands in WPF are:

  1. Application Commands: File Level Commands like Open, Save, Cut, New etc.
  2. Edit Commands: It enables editing.
  3. Component Commands: It allows commands like Scroll-up and Scroll-Down that helps to navigate within a section of text.
  4. Media Commands: It enables multimedia functions such as Play, Pause.
  5. Navigation Commands: Commands for navigation

What is prism and its use in WPF?

Prism is a guide that lays down the best practices for developing large-scale applications that allow flexible development and maintenance.

It is useful in WPF because:

  • Prism allows easy development, testing and integration of components and in various applications, at the component level by reusing of unit-tested components.
  • It becomes easy to extend applications with Prism as it enables easy integration and replacement of components at run time.
  • Increased flexibility of applications allows easy updates of new capabilities using common services and components.
  • Prism encourages team development through independent development and deployment by different teams to different parts of an application.
  • The quality of applications is greatly boosted through Prism that makes fully tested components and services available to the developers.

What is attached property in WPF

An attached property is a special type of dependency property in WPF. It can be added to any WPF object which derives from a dependency object.

For example 

For example, Canvas panel in WPF has four properties ie. Canvas.Left, Canvas.Top, Canvas. Bottom and Canvas.Right, in this Left, Top, Bottom, Right are attached properties of Canvas. 

What is a resource dictionary in WPF?

In WPF, a resource dictionary contains the definitions of the various object as resources so that it may be accessed from another place for reuse.

How to use the resource dictionary?

The XAML code to look up a resource in the resource dictionary is as follows:

<Page

    x:Class="MSDNSample.MainPage"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <Page.Resources>

        <Style TargetType="Button" x:Key="yellowButtonStyle">

            <Setter Property="Background" Value="yellow"/>

        </Style>

    </Page.Resources>

</Page>

 


×