WPF interview Questions
WPF or Windows Presentation Foundation is a Graphic related task that displays user interfaces, images, movies, etc. Every year, .NET and such other interviews are held to fill up the vacancies with the good pay scale. This field is like the ocean where anything can be asked for the interview. Here, is a set of twenty questions that will give an idea of what to expect for your WPF interview. There is no less or more preparation for this particular interview.
So, all you have to do is start with basics and then move on to the complex ones. These questions will help you understand the pattern of the interview that will get you mentally prepared for the big day. It’s not just about being physically prepared, but you have to be mentally prepared as well. So let’s start with questions and their answers that have a higher probability to be asked by the interviewer.
1. Define is WPF and state its advantages?
WPF denotes Windows Presentation Foundation, which is a re-invention of a UI that uses WPF for Desktop applications. Just like other developers have been doing all this while, other than dropping controls on “Windows Forms,” WPF is known to provide an extra rapid boost to the application development including animation, Rich User Interface, and much more.
To summarise it all, following things can be done using WPF:
- Draw Graphics and normal controls.
- Transforming objects including controls, video, and shapes,
- Can easily play/load video and audio files.
- Can create and animate 3D graphics.
- Can provide smooth graphical effects such as color gradients and drop shadows.
- Can use shared styles which can be used across the same controls to provide the same theme, skin, and design.
- Can easily be used to draw vector graphics that scale without jagged aliasing.
Advantages of WPF are:
- Resolution independence
- Tight multimedia integration
- Hardware acceleration
2. What do you understand by Content Alignment in WPF?
In WPF, various properties are used while dealing with the content of content controls. The two properties are as follows:
# Horizontal Content Alignment, and
# Vertical Content Alignment
The parent class of all controls in WPF defines all the properties in System.Windows.Controls.Control class that is.
If we create a TextBox control and a UI with a Button, the UI looks like the following figure where the default vertical and horizontal alignment of the content of a Button is center. The default horizontal and vertical alignment of the content of a TextBox is left and top.
3. What is the value converter in WPF?
A Value Converter is known to function as a bridge between a source and a target that is necessary when a target is bound with one source, for example, if you have a text box then you also has a button control. You want to disable or enable or disable the button control when the text of the text box is null or filled.
Sometimes the string data needs to be converted into Boolean. This is only possible when using a Value Converter. For implementing Value Converters, it requires you to inherit from I Value Converter in the System.Windows.Data namespace and then implement the two methods Convert Back and Convert.
You may note that in WPF, binding helps in the flow of data between the two WPF objects. The bound object that emits the data is called the Source, and the other (that accepts the data) is called the Target.
4. What is the need of WPF when we had windows forms?
The need for WPF can be better be understood with A-G that is,
- A – Anywhere execution (Windows or Web)
- B – Bindings (less coding)
- C – Common feel and look (resource and styles)
- D – Declarative programming (XAML)
- E – Expression blend animation (Animation ease)
- F – Fast execution (Hardware acceleration)
- G – Graphic hardware independent (resolution independent)
5.What are dynamic and static resources?
There are two types of resources:
- Static resource
- Dynamic resource
We should use the Static Resource markup extension to define the resource as a static resource. The value of Static Resource is determined at the time of loading.
Dynamic Resource is used in a situation where the value of the property needs to be changed at runtime.
6. What is a Prism in WPF?
7. What are different kinds of Templates in WPF?
In WPF, templates are a very important part of user interface design. The three main types of templates of WPF are:
- Items Panel Template
- Control Template
- Data Template
8. What can you do in Expression Blend that you cannot do in Visual Studio?
To blend expression in a Visual Studio
- Configure visual states
- Configure brushes and gradient brushes in the properties window
- Configure object timelines
- Configure sample data
- And many other design features
9. List some common Localization or Globalization practices for Localizing or Globalizing WPF?
Some common localization or globalization practices for localizing or globalizing WPF are:1) Use Resources.resx,
2) Use BAML,
3) Use a Resource Dictionary to manage localizable strings.
10. What do you understand by a Routed event and what are its types?
A Routed Events is all about the Hierarchy of the controls that are used by us in the Events. Routed Events are known to be a new Infrastructure that is given by WPF that permits events to go tunneling down the tree to the target elements or Bubble up to the Root element. Events are simply like normal events. Types of routed events
Basically Routed Events are of mainly three types that are as follows:
- Tunneling Events
- Bubbling Events
- Direct Events
11. In WPF, what do you understand by Rotate transform?
12. What do you understand by Virtualization in WPF?
13. List some of the best practices of using WPF in case you are planning to build a Localized/Globalized application?
- You can write UI in XAML
- Avoid positioning and sizing but lets the objects flow automatically
- Enables text wrapping
14. What does Polyline stand for in WPF?
15. You need to display a list of items. Which controls are possible options are made available to you if you need to display a list of items? Of those, which would you use and why?
Some of the possible options for controls available are;
It is important to make sure that the ListView and ListBox can be selected when ItemsControl is not supporting a selection. You must also know that a ListView is more feature rich as it inherits ListBox that inherits ItemsControl and then adds features. You must also make sure that they understand the importance of DataGrid and how it is different from rest and why they must display a list in a DataGrid.
16. What is MVVM?
When you are planning to make applications in WPF, then you need framework named Model View View Model or MVVM. It is same as the MVC framework and has a 3-tier architecture with one more layer. We can do loose coupling using MVVM.
MVVM was originally introduced by John Gossman in the year 2005 specifically for use with WPF as a concrete application of Martin Fowler’s broader Presentation Model pattern. The implementation of an application, Based on the MVVM patterns the implementation of an application uses different platform capabilities that are available in some form for WPF, Silverlight Desktop/web, and on Windows. Many commercial applications, including Microsoft Expression products, were built following MVVM.
17. What is WPF TextBlock?
18. What are different types of Command in WPF?
Sometimes, there arises a need to perform the same activity, for that purpose WPF provides us with a feature called Command to make our work faster and easier. A Command is called on for several purposes. First of all, it is used to separate the semantics from the object that calls upon a command from the logic that executes a particular command.Commands are also used to share grouped actions inside an application in various ways.
There are mainly four types of Command:
- Edit Commands
- Application Commands
- Media Commands
- Component Commands
19. What is tree view in WPF? How can we delete a tree view in WPF?
When you want to represent a data in a hierarchical view, which is in a parent-child relationship and where a parent node can be collapsed or expanded than a TreeView is called into the scene. The left sidebar of Windows Explorer is a good example of the TreeView.A WPF TreeView control in XAML is represented by the TreeView tag.
20. What do you understand by WPF AccessText Control?
In WPF, the AccessText control is used to convert a character that is preceded by an underscore to an Access Key. The Access Key is registered and therefore used to raise an event when pressed.
These questions and answers will help you understand the pattern and way to face the interview in the right manner. You need to understand the correct approach to face the interview. With a bit of research, you can excel in this field. To enhance your knowledge in this particular field you can go through some more articles and expected questions. All the best!