WPF Interview Questions

Last updated on Nov 07, 2023

Windows Presentation Foundation (WPF) is one such tool that helps developers in building applications by separating the UI framework. It uses the Extensible Application Markup Language (XAML) with the .Net framework for development. In this post, we will explain about the top 30 WPF interview questions. Go through the below frequently asked WPF interview questions and answers to elevate your learning curve.

Most Frequently Asked WPF Interview Questions

1. List the components of WPF architecture.

Ans: WPF architecture consists of 5 main components.

  • User32 - It defines what goes where on the screen.
  • DirectX - It talks with drivers and renders the content. 
  • Milcore - The media integration library (Mil) works as a bridge between WPF managed and DirectX / User32 unmanaged API.
  • Presentation core - It is an API used for 2D, 3D, geometry, etc.
  • Presentation framework - It contains application building features like layouts, content, and application controls.

2. Explain about content alignment in WPF.

Ans: Content alignment is used to change the position of text in text boxes and buttons. The content alignment is of 2 types - horizontal content alignment and vertical content alignment. These properties are set in the System.Windows.Controls.Control class. The left and top are the default vertical and horizontal alignment of the content of a text box. The center is the default alignment of content on a button.

3. What are the resources in WPF?

Ans: In WPF, resources enable the developers to reuse commonly defined objects and values. Using resources, we can set properties of multiple controls at a time. If we define a resource for an element, the same will be applied to the child elements of that element too.

4. What are the types of documents supported by WPF?

Ans: WPF supports two types of documents. 

  • Flow format - It alters the content to fit the screen size.
  • Fixed format - It shows the content irrespective of the screen size.

5. What is XAML in WPF and what is the use of it?

Ans: The Extensible Application Markup Language (XAML) is used to instantiate .NET objects. It describes the objects, properties, and the relation between them. It helps in writing user interfaces for web applications by creating graphical and non-graphical objects. In WPF, XAML is used to encompass the elements of content like controls, documents, and vector graphics. 

6. What are WPF styles?

Ans: The styles in WPF are resources that allow developers to apply some properties to the controls all over the application. We can set the existing properties of an object like width, height, size, font, etc. The styles can be applied to the parent element, root element, current element, and on the application level.

7. What is the difference between Visibility.Collapsed and Visibility.Hidden in WPF?

Ans: 

  • Visibility.Collapsed - It does not reserve the whitespace and does not render the control. It will just collapse the space the control would take.
  • Visibility.Hidden - It hides the control and renders whitespace. But it reserves the space it occupies in the layout. 

8. What is the difference between static and dynamic resources in WPF?

Ans:

  • The static resources are evaluated only once by the element at the time of loading. The dynamic resources can be manipulated at runtime and are evaluated at runtime.
  • The static resource is light, and the dynamic resource is heavy.
  • To define a resource as a static resource, we should use the StaticResource markup extension. To define a resource as a dynamic resource, we should use the DynamicResource markup extension.

9. What is a value converter in WPF?

Ans: A value converter works as a bridge between a target and a source. It is required when a target is bound with one source. The value converter can convert the string data to Boolean. To use a value converter, we should inherit it from the I Value Converter in the System.Windows.Data namespace.

10. Explain the types of controls in WPF.

Ans: Controls in WPF are of 4 types.

  • Control - It is a basic control like a text box, labels, buttons, etc. 
  • Shape - It is used to create simple graphic controls like line, rectangle, ellipse, etc.
  • Panel - It is used to align and position the controls.
  • Content presenter - It is used to add dynamic controls on a WPF screen. We can place any XAML content inside the control.

11. What is the difference between xmlns and xmlns:x in WPF?

Ans: Xmlns is the default namespace used to resolve overall WPF elements. The xmlns:x is used to resolve the XAML language definition.

WPF Training

  • Master Your Craft
  • Lifetime LMS & Faculty Access
  • 24/7 online expert support
  • Real-world & Project Based Learning

 

12. What are freezable objects in WPF?

Ans: A freezable object is an object that has its state locked down, so it becomes unchangeable. When an object is frozen, we cannot modify it. When an object is unfrozen, it behaves like any other object. The freezable objects perform better, and they are safer to share between threads.

13. Tell the methods present in the DependencyObject.

Ans: The DependencyObject has the following methods in it.

  • SetValue
  • ClearValue
  • GetValue

14. Explain about PRISM.

Ans: PRISM is a framework to create complex applications in Silverlight and WPF that have a single code base. It divides a complex application into simpler modules. It helps to build rich and flexible desktop applications easily. It uses Command Patterns, DI, IC, Separation of Concerns, MVVM, etc.

15. Can we use windows forms in a WPF application?

Ans: We can use Windows Forms in a WPF application. It can appear as a WPF popup. Instead of dropping controls on windows forms, we can place them beside WPF controls.

16. What are the common assemblies used in WPF?

Ans: There are three assemblies in WPF.

  • WindowsBase.dll - It represents the base infrastructure of WPF. It also includes dependency properties support.
  • PresentationCore.dll - It has types that form the foundation of the WPF GUI layer.
  • PresentationFoundation.dll - It defines the WPF controls types, data binding support, animation, multimedia support, any other services.

17. List the types of windows in WPF.

Ans: WPF consists of three types of windows.

  • Normal Window
  • Page Window
  • Navigate Window

18. What is the syntax for resources in WPF?

Ans: The syntax for resource is,


  

     

   

  • ElementName - It is the name of the element that uses the resource.
  • PropertyName - It is the property that takes its value from the resource.
  • MarkupExtension - It defines the type of resource.
  • KeyName - It is the unique name to identify the resource.

19. Explain about routed events in WPF.

Ans: All the elements in a WPF application are set in an element tree relationship. Routed event is similar to a normal event, which helps with the hierarchy of the controls. Routed events help the events to tunnel down the tree to the target elements or bubble up to the root element. The routed events are of 3 types - bubbling events, tunneling events, and direct events.

20. List the various layout panels in WPF.

Ans: The WPF comes with the below five built-in layout panels.

  • Grid
  • Canvas
  • StackPanel
  • DockPanel
  • WrapPanel

21. What are the important subsystems in WPF?

Ans: The following are the important subsystems in WPF.

  • Object
  • Windows.FrameworkElement
  • Windows.Controls.Control
  • Windows.DependancyObject
  • Windows.UIElements
  • Windows.Media.Visuals
  • Threading.DispatcherObject
  • HKR Trainings Logo

    Subscribe to our YouTube channel to get new updates..!

  •  

22. What is custom control?

Ans: When the built-in controls do not satisfy your needs, you can create a custom control. If you want to add extra functionality or an extra property, you can create a custom control. Custom control helps in creating feature-rich and customizable controls. The best way to make a control library is through custom control. It offers its own style, theme, and template defined in generic.xaml. 

23. Explain about command design patterns in WPF.

Ans: The command design pattern is under the behavioral design patterns category. It decouples the request of action from the object. It represents an action as an object. It does not contain an executable functionality. It promotes loose coupling by removing the direct link between the functionality and the command definitions. The command design pattern lets developers implement operations based on the user request. The members of the command design pattern are,

  • Invoker
  • Receiver
  • Client
  • Command
  • Concrete Command

24. What is the difference between Style and ControlTemplate?

Ans:

  • Styles are used to setting a bunch of properties on controls. We can reuse the styles to standardize controls. Styles can be applied to a certain type or set explicitly on controls. 
  • A ControlTemplate defines the appearance of the control. They specify how the controls are rendered. If we want to change the look of control by simply changing the ControlTemplate of a control.

25. What is the difference between Visual and Logical Tree?

Ans: 

  • A visual tree consists of all logical elements along with the visual elements of the template of each element. It is responsible for rendering visual elements, hit testing, relative source, propagating element opacity, etc.
  • All the elements in WPF will be in a hierarchy. A logical tree defines the relations between elements of the user interface. It is responsible for forwarding routed events, inherits dependency property values, resolves dynamic resources references, etc.

26. Explain about Dispatcher Object in WPF.

Ans: A Dispatcher object represents an object that is associated with a Dispatcher. When a WPF application is executed, it automatically creates a new Dispatcher object. Two threads will be created when a WPF application starts - Render thread and UI thread. The Dispatcher will be associated with the UI thread. The Dispatcher object can only be accessed directly through the thread that the Dispatcher was created on.

27. What are the view and view models in MVVM?

Ans: The view is the layout, structure, and appearance of what the user sees on the screen, i.e., the user interface. It receives user's interaction through a click, keyboard, gestures, etc. It uses data binding to forward these interactions to the view model.

The view model is actually a logic that functions as a link between model and view. It retrieves data from the model and exposes it to the view. It can be described as a state of the data in the model. The view model does not have a reference to the view. Instead, it binds directly properties on the view model.

28. What is a trigger in WPF?

Ans: A trigger is defined to perform an action on a change of any property value or when an event fires. They are used in styles, and they create a visual effect on controls. The following are the triggers provided in WPF.

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

29. What is the difference between events and commands in the MVVM Model?

Ans: Both commands and events are related to each other. Unlike events, commands can be associated with any number of UI Controls or Input Gestures. The events don't really fit into the MVVM paradigm. So, we generally use commands in WPF MVVM architecture. 

  • An action in Events is tightly coupled with its source. We can easily maintain various actions in a single place with the help of commands.
  • The events cannot be reused freely. the commands can be reused anywhere in the application.

WPF Training

Weekday / Weekend Batches

 

30. What is an adorner?

Ans: An adorner is a special framework element that is bound to the UI element and rendered on a surface above the element. This surface is called an adorner layer. We can extend controls by adding extra visual functionality using adorners. They are also used to add handles to elements that provide visual clues to the user.

Conclusion

Ans: Strong skills in .NET programming is a prerequisite for WPF developers. If you are an experienced WPF developer, knowledge of coding implementation best practices, multithreading concepts, design patterns, integration testing, and unit testing will be an added advantage. You should be able to react to problems on the go and correct the program as necessary. The job opportunities for WPF are still high in number. So, prepare well and crack the interview for your dream job.

About Author

As a content writer at HKR trainings, I deliver content on various technologies. I hold my graduation degree in Information technology. I am passionate about helping people understand technology-related content through my easily digestible content. My writings include Data Science, Machine Learning, Artificial Intelligence, Python, Salesforce, Servicenow and etc.

Upcoming WPF Training Online classes

Batch starts on 18th Nov 2024
Mon & Tue (5 Days) Weekday Timings - 08:30 AM IST
Batch starts on 22nd Nov 2024
Sat & Sun (6 Weeks) Fast Track Timings - 08:30 AM IST
Batch starts on 26th Nov 2024
Mon & Tue (5 Days) Weekday Timings - 08:30 AM IST
WhatsApp
To Top