Dot Net For All

WPF interview most frequent question and answers

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.

WPF Interview Questions And Answers

Lets get started with the most frequent WPF interview questions.

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.

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

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.

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.

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.

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

 

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.

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.

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.

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.

DataTemplate, ControlTemplate, ItemTemplate

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.

INotifyPropertyChanged, IValueConvertor, INotifyDataErrorInfo, IDataErrorInfo

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.

INotifyDataErrorInfo, IDataErrorInfo, Validations using Exceptions and Validation Rules.

StackPanel, Grid, Canvas, Dockpanel, UniformGrid, Wrappanel

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 the decorator design pattern.

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.

 

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.

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.

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.

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

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.

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.

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

 

Top career enhancing courses you can't miss

My Learning Resource

Excel your system design interview