WPF Interview Questions And Answers

Ratings:
(4)
Views:763
Banner-Img
  • Share this blog:

 

WPF Interview Questions And Answers

Q1. Explain WPF?

Ans: Windows Presentation Foundation (WPF) is a User Interface(UI) framework that creates client desktop applications. It supports a set of application development features such as application model, controls, graphics, documents, layout, data-binding, resources, and security. It uses the XAML to provide declarative programming.

Q2. What are the advantages of WPF?

Ans: The advantages of WPF include:

  • The use of 3D graphics, HD video, speech, and rich document viewing in windows 32 allows consistent programming models.
  • WPF uses vector graphics to make the application resolution-independent.
  • It works with a Graphic Processing Unit (GPU) to provide WPF applications with hardware acceleration, to give smooth graphics and enhanced performance.
  • It uses declarative programming to define the layout of application objects.
  • Easy to deploy Traditional Windows applications.

Q3. Name the types of document controls supported by WPF?

Ans: There are two types of document controls that support WPF. They are:

Flow Format document: It is to alter the content in the document to fit on the screen size.

Fixed Format Document: It presents the content irrespective of screen size.

Q4. Define XAML and its uses?

Ans: XAML is an Extensible Application Markup Language. It is easy to define objects and properties in XML. 

XAML is used to describe objects, properties, and relation. It helps to create graphical or non-graphical objects.

Q5. What is Content Alignment? Mention the types of properties of Content Alignment?

Ans: Content Alignment is to maintain the position of content on the screen. There are two different properties of Content alignment, one is Horizontal content Alignment and the other is Vertical content Alignment.

These two properties are defined in System.Window.Controls.Control class which is the parent class of all controls in WPF.

Q6. Define resources in WPF? Write the syntax of resources in WPF?

Ans: Resources in WPF provide a simple way to reuse defined objects and values. It allows setting the properties of multiple controls at a time.

Syntax for resources in WPF:





Where,

Element Name is the name of an element that uses the resource.

Property Name is the name of the property that takes its value from resources.

Markup Extension defines the type of resources.

KeyName is a unique string to identify the resources.

Q7.Mention the types of resources?

Ans: There are two types of resources in WPF

Static resources: To define a static resource we use Static resource markup extension and its value is determined at the time of loading.

A sample problem, add the code given below in Window1.xaml file.



         

Dynamic resources: It is used to change the value of the property at the time of a run.

A sample problem, add the code given below in Window1.xaml file.



     

Open the code behind, add the snippet code given below.

private void Button_Click(object sender, RoutedEventArgs e)  {  

this.btn.SetResourceReference(BackgroundProperty, "brush");  } 

Q8. What are Freezable objects in WPF?

Ans: Freezable objects are the special objects that have two states: one is Frozen where the objects can no longer be modified, and the other is Unfrozen where objects seem to behave like any other object.

Frozen freezable objects perform better and are also safe when it is required to share between threads.

Q9. Name the assemblies used in WPF

Ans: 

  • Presentation Foundation
  • Presentation core
  • Windows base

Q10. Mention the difference between Silverlight and WPF?

Ans: 

Silverlight WPF
Silverlight is based on smaller or larger compact CLR but not with a full breadth WPF is based on Off Desktop CLR with the full version.
User can create only in Browser-based Applications (XAP) User can create in XBAP Application, Navigation App, and Windows App
It supports Direct and Bubbling routed events. It supports 3 types of routed events Direct, Tunnel, and Bubbling.
It does not support Multi-binding. It supports Multi-binding.
It supports XML Data provider. It supports XML and Objects Data provider.

Q11. What is Dependency property?

Ans: Dependency property is the value that depends on the external, sources such as visual tree inheritance, animation, data binding, styles. It has the in-built feature of providing notification when the property has changed.

Q12. Name the methods present in Dependency objects?

Ans: There are three methods present in Dependency objects. They are:

  • Set value
  • Clear value
  • Get value

Q13. What are the types of Windows present in WPF?

Ans: WPF has three types of Windows.

  • Normal Window
  • Page Window
  • Navigation Window

Q14. Explain the Routed event in WPF?

Ans: A routed event that can invoke users on multiple listeners in an element tree rather than the object that raised an event. It is a CLR event supported by an instance of the routed event class.

Q15. What is a Value converter in WPF?

Ans: A value converter is a converter that acts as a bridge between the target and the source. It converts the string data to Boolean. It is necessary when a target is bound with one source, for instance, you have a textbox and button control. 

To implement a value converter, it is required to assume from I value converter in the system.Windows.Data namespace and implement the two methods Convert and Convert back.

Q16. Explain Prism in WPF?

Ans: Prism is a framework that helps to design and build rich, flexible, easy to maintain WPF applications. It provides an implementation of a collection of design patterns that helps to write structured and maintainable XAML applications which includes event aggregation, MVVM, commanding, dependency injection and many more.

Q17. Define MVVM and its advantages?

Ans: The Model View Viewmodel (MVVM)  is a process of creating a client application that leverages the features of the WPF application, allows for a simple unit of testing functionality, to works with less technical difficulties. 

Advantages:

  • Separates User interface and Business layers as view and view model
  • Code sharing between page and forms
  • Easy to maintain
  • Modularity
  • Test-driven approach

Q18. Write the difference between MVVM and MVC?

Ans: 

MVC
MVVM
Stands for Model View Controller
Stands for Model View ViewModel
An Architectural pattern which is used for developing UI that divides an application into three interconnected parts such as Model, View, and Controller
A software Architectural pattern used for separation of Development of GUI and the development of Business Logic and back-end logic 
The model represents Data, View represents UI, and Controller handles requests
The model represents objects, View represents UI layer, and ViewModel describes the binding between View and model 
It was used by java springs  and ASP.NET
It was used by WPF, Angular JS, and Silverlight

Q19. Explain the MVVM pattern?

Ans: Model View ViewModel (MVVM) pattern divides the User Interface code into three parts. They are

Model: It is responsible for data extracted by WPF. It must implement INotify Property Changed as appropriate.

View: It is a code that agrees with the visual representation of data. It is defined by XAML and binds to the view model by using Data binding only.

ViewModel: It is a layer that binds with View and Model together. It exposes the data relevant to view and easy to understand by the user. It also controls how view interacts with the application.

Q20. What are the various Layout panels in WPF?

Ans: 

  • Stack panel
  • Dock panel
  • Grid panel
  • Wrap panel
  • Canvas panel

Q21. Why layout panels are required in WPF?

Ans: Layout panels are required to arrange the group of GUI elements in the application. A fixed pixel arrangement doesn’t work when the application screen is set to be on a different screen resolution. Hence layout panels help to arrange these elements.

Q22. Mention the important subsystems of WPF?

Ans: The major subsystems are:

  • Windows.Controls.Control
  • Windows.FrameworkElement
  • Windows.DependencyObject
  • Windows.Media.Visual
  • Object
  • Windows.UIElement
  • THreading.DispatcherObject

Q23. Define Custom control in WPF?

Ans: Custom control is a class that consists of its own style and theme which are defined in generic.xaml file. It is used when the controls need to support theme and style. It also extends or adds its functionality to fit in the scenario.

Q23. Explain Serialization?

Ans: Serialization is the process of converting a state of objects into a stream of bytes.

Q25. What is Data Binding in WPF?

Ans: Data Binding is a process of getting information from one object to another and displaying it in one or more elements in the User Interface. It is one of the important features of XAML that binds simple data for displaying single value and binds complex data for displaying and formatting a bunch of data. The binding in XAML syntax is {binding….}.

Q26. Name four general kinds of elements of XAML?

Ans: The four general kinds of elements of XAML are:

  • Root element
  • Panel element
  • Control element
  • Geometric element

Q27. What is the unit of measurement in WPF?

Ans: All measurements are made in WPF are pixels. One pixel is 1/96th part of an inch. These pixels are measured as double, this results in the end value as a fractional value

Q28. Write the difference between XAML and XML?

Ans: XAML is an Extensible Application Markup Language. It is used to write a user interface for next-generation applications.

XML is an Extensible Markup Language. It is designed to store the data or to work with stored data.

Q29. Write a code to display HELLO WORLD in XAML?

Ans: Displaying HELLO WORLD





HELLO WORLD!



Q30. Mention the Namespace required for working with 3D

Ans:  The Namespace required for 3D is System.Windows.Media.Medi3D.

Q31. What is the need for WPF when we had windows forms?

Ans.

A - Anywhere execution ( Windows or Web)

B - Bindings ( less coding)

C - Common look and feel ( resource and styles)

D - Declarative programming (XAML)

E - Expression blend animation ( Animation ease)

F - Fast execution ( Hardware acceleration)

G - Graphic hardware independent ( resolution independent)

I would strongly suggest you see the below video which explains all the above A to G points practically.

Q32. Describe how you would go about writing your own button style?

Ans. Make sure the interviewee understands the following: – How to copy the default style using Expression Blend. – How to change the style – How there must be a Style for each state: Enabled, Disabled, Mouseover, pushed, etc…

Q33. You need to display a list of items. Which controls are possible options? Of those, which would you use and why?

Ans. ItemsControl, ListBox, ListView, DataGrid.

– Make sure they know that ListBox and ListView can be selected while ItemsControl does not support selection. – ListView is more feature-rich, as it inherits ListBox, which inherits ItemsControl, and adds features. – Make sure they understand what a DataGrid is and how it is different and why they would display a list in a DataGrid.

Q34. What can you do in Expression Blend that you cannot do in Visual Studio?

Ans. Configure brushes and gradient brushes in the Properties window. Configure the Visual States. Configure sample data. Configure Object Timelines Animation Many design features…

Q35. What are some best practices when using WPF if you plan to build a Localized/Globalized application?

Ans. Write UI in XAML Avoid sizing and positionings, but let objects automatically flow. Enable TextWrapping.

Q36. What the initial class that is loaded by any new WPF Application project?

Ans. The initial class loaded using WPF application project is App.App.xaml and App.xaml.cs, even App is also acceptable.

Q37. Name some common Globalization/ Localization practices to Globalize/Localize WPF?

Ans.

  • Use a ResourceDictionary to manage localizable strings
  • Use Resources.resx
  • Use BAML

You liked the article?

Like : 0

Vote for difficulty

Current difficulty (Avg): Medium

Recommended Courses

1/15

About Author
Authorlogo
Name
TekSlate
Author Bio

TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills in the market.


Stay Updated


Get stories of change makers and innovators from the startup ecosystem in your inbox