WPF interview most frequent question and answers

By | May 30, 2017

Hello, In this article I will discuss about the most frequently asked WPF interview questions and their answers. In my previous articles I have discussed about C# and OOP interview question. You can find their link mentioned below.

Become an Expert in Programming and Web Development.View all courses!

WPF Interview Questions And Answers

Lets get started with the most frequent WPF interview questions.

  • What is dependency property?

Dependency property is a special kind of property introduced in WPF. This property helps in data binding the source and target object. Dependency property has been designed to reduce the memory footprint.  These properties are static in nature.

  • What is the advantage of dependency property?

Dependency property are static in nature. It means they are not initialized for each and every control they are associated with.

  • Since dependency property are static in nature. How they are handled at control level providing a different value for each control?

WPF stores dependency property in a special way. These properties are stored in a property bag which is dictionary of key value pair. In this property bag each and every dependency property is stored with default value.

For a control which assigns a value different from the default value, it is stored explicitly for that control.

  • Can we create a dependency property in any class?

No we cannot create a dependency property in any class.  It can be only created in classes which derive from DependencyObject class. You can read more about dependency property in WPF in this article.

  • What is attached property and how is it different from dependency property?

Attached property are again dependency property in WPF. These are used to extend the functionality of a control. These are analogous to extension methods in C#. . They can be used to receive a notification of a change of them self since they are a type of Dependency Property but one of the differences that these properties have is that they are not defined in the same class they used, unlike DPs.

  • Give an example of attached property in WPF framework?

Grid.Row and Grid.Column are good example of Attached property in WPF. You can read more about attached property in this article.

  • What are markup extensions?

 

  • How is WPF development different from win forms development?

We can develop in WPF based on MVVM design pattern which in turn helps the developer and designer to work independently. The UI is not tightly coupled to code.

The code is more easily unit testable as we can create the unit tests on the methods.

The controls can be easily customized, thanks to the power of XAML.

  • What are different type of binding modes present in WPF?

Different binding mode in WPF are:

One Way, One Way To Source, Two Way and Default. You can learn more about binding in this article.

  • What is a style in WPF?

Styles help us to define a custom look to the control in WPF. Styles in WPF have been introduced to have a consistent look and feel of UI. E.g. all the buttons in our application should have same color, height , width and other properties. You can read more about styles in this article.

  • What are different types of styles present in WPF?
  • What is a template in WPF?

Templates in WPF are used to provide the customized UI to the controls.  Each and every control in WPF cmoes with default template. This template can be customized by  providing user defined styles and setters.

Moreover we can also change the default behavior of the control.

  • What are different types of templates present in WPF?

DataTemplate, ControlTemplate, ItemTemplate

  • What are different ways we can bind view and view model in WPF?

We can bind WPF view and view model in two ways:

View First Approach And Model First Approach. You can read more about them in this article.

  • Can I create a control template for TextBox control?
  • What are most commonly used interfaces in WPF?

INotifyPropertyChanged, IValueConvertor, INotifyDataErrorInfo, IDataErrorInfo

  • What is the use of INotifyPropertyChanged interface?

This interface is used to notify the UI. Since the UI and model in decoupled in MVVM design pattern, this interface implementation provides an event named PropertyChanged which is raised when the property values in changed.

  • What are different types of validation present in WPF for validating UI?

INotifyDataErrorInfo, IDataErrorInfo, Validations using Exceptions and Validation Rules.

  • What are different types of panels in WPF?

StackPanel, Grid, Canvas, Dockpanel, UniformGrid, Wrappanel

  • What is MVVM?

MVVM is a design pattern used for separation of concern in WPF. It helps in the development of WPF application where designer and developer can work independently.

You can read more about MVVM design pattern in this article.

  • Attached properties are based on which design pattern? 

Attached properties are based on the decorator design pattern.

  • What is IValueConvertor and why is it used in WPF?

IValueConvertor in WPF is used to bind two source and target properties.  Binding class contains a property of type IValueConvertor which can be set in XAML.

You can read more about IValueConvertor in this article.

  • What is difference between ItemTemplate and DataTemplate?

 

  • What is a content control in WPF?
  • What are different type of routed events in WPF?

Routed events are special types of events provided in WPF. There are basically three type of routed events in WPF. They are Direct Events, Bubble events, and Tunnel events.

You can read about all these events in this article.

  • What is thread affinity in WPF?

In WPF each control is owned by a thread. If some other thread is trying to update the control we will get an exception. This is known as thread affinity.

  • How to access the control from different thread?

If we want to update the contents of a WPF control from the different control we can use the dispatcher. Dispatcher is used to transfer the control from a custom thread to UI thread.

  • What is observable Collection?
  • What is difference between measure override and arrange override?

To read about measure override and arrange override you can read this article.

  • What is difference between static resource and dynamic resource?

Static Resource – These resource are resolved at complied time. Once we set a style for the control in static resource we cannot change it at run time.

Dynamic Resource – It can be used to change the control style at run time.

  • What is a content presenter?

Content presenter is used to add a placeholder for the content control. You can see how I have used the content control in this article.

  • How to execute a button click event in the View Model?
  • What are the different methods available in the ICommand interface?
  • When the CanExecute method of the ICommand interface is executed?

In this article I have discussed various WPF interview questions and their answers. Hope it will help you.