WPF Interview Questions

Table of Content : Click To Go
Goto Category WPF :Click to Go

Q1. What is WPF ?

Ans. WPF stands for Windows Presentation Foundation. From its name we can conclude that it is for building windows applications. It is introduced in .Net framework 3.0. Main usage of WPF is to provide rich graphical interface. Read more

Q2. What is Style in WPF ?

Ans. As the name tells it is a way to customize or personalize the look or appearance of objects. A style is a collection of values which represents properties of a specified control. We can assign certain set of styles collectively for a specific type of control ( like all buttons, all textboxes etc) or restrict the style to be used only by those controls which you want explicitly with the help of keys(x:key). Read more

Q3. What are Templates in WPF ?

Ans. WPF allows you to completely change the visual appearance of a control and representation or Structure of data. Templates in WPF allow you to fully change the UI of anything.
There are two types of Templates in WPF:
1. Data Template
2. Control Template
Read more…

Q4. What are Triggers in WPF ?

Ans. A Trigger sets properties or starts actions, such as animation, when a property value changes or when an event is raised. Triggers are used in styles to perform some actions. Triggers create visual effects on controls. By using Triggers we can change the appearance of Framework Elements.
There are three types of Triggers available.
1. Property Trigger
2. Event Trigger
3. Data Trigger
Read more..

Q5. What is Dependency Property in WPF ?

Ans. WPF introduces a new property called Dependency Property or shortly you may like to call it as DP. Dependency Property comes with some enhanced features in addition to normal CLR Properties.

A lot of features come with DP. A Dependency Property is a Property whose value depends on the external sources, such as animations, data bindings, styles, or visual tree inheritance. Not only this, but a Dependency Property also has changed, data binding and styling.

One important thing to keep in mind is that Dependency Properties are declared as static. Because Dependency Property is maintained and declared at class level. All the objects of the class use the single property declared on class level instead of using individually. Read more

Q6. What is Attached Property in WPF ?

Q7. What is Data Binding in WPF

Ans. Data Biding in WPF is a way how the data is communicating between the source and target. It is simply updating the data in view(application UI) with respect to data in the view model(presentation logic) and vice versa. Read more

Q8. What is the Data Binding Modes in WPF ?

Ans. It is a property of Binding class which is set during the binding indicates the direction of the data flow.

Four type of Modes are there in WPF. They are:

  • OneWay : Target is updated when source changes
  • TwoWay : Target is updated when the source changes, and similarly, the source is updated when the target changes.
  • OneWayToSource : Only the source is updated when the target changes.
  • OneTime : Target is updated only the first time the source changes.

Read more

Q9. What is Converter in WPF ?

Ans. Converter are used in Data Binding. Converters are used when the source and target types are different, or when the target must have a different value than that of the source. Read more

Q10. What is UpdateSourceTrigger in WPF ?

Ans. It is one of the property of Data Binding. As the name suggests that it defines timings when should the source will reflect changes if the target gets updated. So we have two modes which updates the source. They are TwoWay and OneWayToSource.

We have four properties of UpdateSourceTrigger
1. Default
2. LostFocus
3. PropertyChanged
4. Explicit
Read more

Q11. What is RelativeSource in WPF ?

Ans. It is a Markup Extension. RelativeSource is used in Bindings. This Property tells about the source position where it lies relative to a given element. It can be of Four Types.
1. Self
2. FindAncestor
3. TemplatedParent
4. Previous
Read more

Q12. What is INotifyPropertyChanged Interface in WPF ?

Ans. INotifyPropertyChanged Interface is used to notifies the client or your class that one of its property has been changed. And it contains only event ‘PropertyChanged‘ of delegate type ‘PropertyChangedEventHandler‘ which updates that property’s value through its set accessor. Read more

Q13. What are Resources in WPF ?

Ans. Resources are the objects that can be reused in different places in your application. WPF have the ability to store objects and their values as Resource. Resources can be defined locally in a Page / Window / UserControl or globally in a App.Xaml / ResourceDictionary.Xaml (a Managed way to define Resources is inside a ResourceDictionary).
Type of Resources
1. Static Resource
2. Dynamic Resource
Read more

Q14. Difference Between Static Resource and Dynamic Resource in WPF

Ans.
Static Resource
-> Static Resources are the resources that are defined by using StaticResource Markup Extension. The value of these resources are resolved at compile time or before the application runs. This is onetime lookup.
Dynamic Resource
-> Dynamic Resources are those which are defined by using DynamicResource Markup Extension. Value of these resources are resolved at runtime.
Read full list of Differences

Q15. What is Resource Dictionary in WPF ?

Ans. Resource Dictionary is simply a XAML file which stores the resources you want to share across your application. It is a managed way to hold all the global resources at one place. Read more

Q16. What is DataContext in WPF ?

Ans. DataContext is the most basic concept of Data Binding in WPF. It is like providing data source in the binding. It allows elements to inherit data source from its parent.
In a very layman language, DataContext is used to provide communication between ViewModel and View. Read more

Q17. What is Layout in WPF ?

Ans. WPF has a Layout System that take care of element’s layout – how it is positioned, being sized and drawn. A Layout describes the arrangement of its Panel element’s child collection.

In WPF we are provided with some Panel elements, which we generally call them Layout Panels.
1. Canvas
2. StackPanel
3. WrapPanel
4. DockPanel
5. Grid
Read more

Q18. What are Routed Events in WPF ?

Ans. They are the special type of Events that can move up or down the visual tree according to the Routing Strategy. These events can be handled by multiple listeners of the hierarchy or the object that raised the event itself.
WPF Routing Strategies are :
1. Tunneling
2. Bubbling
3. Direct
Read more

Q19. What is Transform in WPF ?

Ans. Transform means to alter the form, nature or appearance. In WPF we have classes for 2-D and 3-D Transform.

WPF provides the following 2-D Transform classes for common transformation operations:
1. Rotate Transform
2. Scale Transform
3. Skew Transform
4. Translate Transform

In this article we first try to explore about 2D Transformation in WPF, What are the different Transform Classes that helps in the Transformation of objects and how we can Transform them. Read full

Q20. What are Freezable Objects in WPF ?

Ans. These are the special type of objects that can have 2 states, one is modifiable (unfrozen) and other is read-only (frozen). When the object is in unfrozen state , it works like normal other objects. In the Frozen state, it is locked for any modification moreover in the Frozen state it can’t even fire events. Read more

Q21. What is ObservableCollection in WPF ?

Ans. ObservableCollection represents a dynamic data collection. It notifies WPF/ Silverlight application whenever an item gets added, removed from the collection or when the whole list is refreshed. ObservableCollection Class is an inbuilt class which implements INotifyCollectionChanged and INotifyPropertyChanged. Read more

Q22. What is Visual Tree and Logical Tree in WPF ?

Ans. In WPF all the elements and components are organised in a hierarchical structure or as a Tree Structure. This object tree structure helps in finding the relation between various elements of the WPF. This tree can be conceptualized in two ways Visual Tree and Logical Tree. Read more

Q23. What are Commands in WPF ?

Ans. Commands are the instructions given to the computer to do something. These can be issued by several ways, may be by keyboard input or by clicking a button etc. Read more

Q24. How to bind Two values in Combobox in WPF ?

Ans. Click here to see full example with explaination.

Q25. What is IDataErrorInfo ?

Ans. WPF provides three ways for Data Validation. As most of the times we have to take input form user or other sources so there is a need of validation logic to ensure that the entered data is valid. WPF gives you the ability to provide visual feedback to the user without throwing exceptions.

Read the following three articles about validation
ValidationRule
IDataErrorInfo
INotifyDataErrorInfo

Q26. What is INotifyDataErrorInfo ?

Ans. Show Answer

Q27. What is ValidationsRule ?

Ans. Show Answer

Q28. WPF Architecture ?

Ans. Show Answer

Q29. What is MVVM in WPF ?

Ans. Show Answer

Q30. WPF Class Hierarchy.

Ans. Show Answer