Latest 50 WPF Interview Questions And Answers Pdf

Latest 50 WPF Interview Questions And Answers Pdf

1. What is the need of WPF when we had windows forms?

A – Anywhere execution ( Windows or Web) (Latest 50 WPF Interview Questions And Answers Pdf)

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 su

2. What is attached property and how is it different from dependency property?

Answer : 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.

3. What are Resources in WPF?

Answer: Windows Presentation Foundation (WPF) resources provide a simple way to reuse commonly defined objects and values. Resources in WPF allow you to set the properties of multiple controls at a time. For example, you can set the background property on several elements in a WPF application using a single resource.

The best way of defining the resources is on a Window or Page element level. Any resource that you define for an element also applies to their child elements of that element. For example, if you define a resource for a Window element that has a Grid as a child element, then the resources defined for the window elements can also be used by the grid element. However, if you define a resource for the grid element, then the resource applies only to the child elements of the grid element.

4. What are the Binding Modes in XAML?

Answer: The DataBinding mode defines the communication direction to the source or the direction of data flow from the source. In XAML (WPF, Silverlight, WP or Win8 App) there are five ways you can bind a data target object to a source.

Binding Modes in XAML

OneWay: Data moves only one direction, the source property automatically updates the target property but the source is not changed.

TwoWay: Data moves both directions, if you change it in the source or target it is automatically updated to the other.

OneWayToSource: Data moves from the target to the source changes to the target property to automatically update the source property but the target is not changed.

OneTime: Data is changed only one time and after that it is never set again, only the first time changes to the source property automatically update the target property but the source is not changed and subsequent changes do not affect the target property.
See for more details:

Data Binding in XAML (WPF, Silverlight, Windows Phone or Win8 App) Part 1

5. What is resource in WPF? How many types of resources in WPF?

Answer: Windows Presentation Foundation (WPF) resources provide a simple way to reuse commonly defined objects and values. Resources in WPF allow you to set the properties of multiple controls at a time. For example, you can set the background property on several elements in a WPF application using a single resource.

The best way of defining the resources is on a Window or Page element level. Any resource that you define for an element also applies to their child elements of that element.

If you define a resource for the grid element, then the resource applies only to the child elements of the grid element.

6. How to set content of a NavigationWindow?

Answer: The Navigation Window class is derived from the Window class, so it inherits all the properties of Windows such as methods, properties and events. The navigation window provides backward and forward buttons for navigating to pages that we have visited before or have yet to visit.

Creating Navigation Paged Application: To create Navigation Window based applications, use a Navigation Window container instead of a Window container as shown in the following picture and the source is the property of the Navigation window and write the name of the page that you want to set as the home page as shown in the following picture:

7. What is BAML?

Answer: BAML, which stands for Binary Application Markup Language, is simply XAML that has been parsed, tokenized, and converted into binary form. Although any chunk of XAML can be represented by procedural code, the XAML-to-BAML compilation process does not generate procedural source code. (Latest 50 WPF Interview Questions And Answers Pdf)

8. What is a routed event?

Answer: Routed Events is about the Hierarchy of the controls you are using in the Events. Routed Events are a new Infrastructure given by WPF that permit events to tunnel down the tree to the target elements or Bubble up to the Root element. Routed Events are just like normal events.

Types of Routed Events

Routed Events are of three types, which are as follows:

Bubbling Events
Tunneling Events
Direct Events
Tunneling Events: Tunneling events are the reverse of the Bubbling events. Tunneling Events raised first in the controls hierarchy. These events are raised by the Root elements. This allows events to tunnel down the tree.

Tunneling Events

Bubbling Events: Bubbling Events are those Events which are first raised by the control than raised by the other controls in the control hierarchy. It allows Bubble up to the tree till the Root Element. First Tunneling events are raised then bubbling events raised.

Bubbling Events

Direct Event: Direct Event is generally raised by the control itself. The behavior of this event is same as the .NET general event.

9. What is meant by WPF?

Answer: Windows Presentation Foundation (WPF) is a next-generation presentation system for building Windows client applications with visually stunning user experiences. With WPF, you can create a wide range of both standalone and browser-hosted applications

10. How many types of Bitmap Effects in WPF?

Answer: Bitmap effects are simple pixel processing operations. A bitmap effect takes a BitmapSource as an input and produces a new BitmapSource after applying the effect.

Bitmap effects enable designers and developers to apply visual effects to rendered Microsoft Windows Presentation Foundation (WPF) content. For example, bitmap effects allow you to easily apply a DropShadowBitmapEffect effect or a blur effect to an image or a button. The unmanaged APIs provide an extensible framework for independent hardware vendors (IHVs) to develop custom effects to use in WPF applications.

The following are the available Bitmap Effects in WPF:

BlurBitmapEffect
OuterGlowBitmapEffect
DropShadowBitmapEffect
BevelBitmapEffect
EmbossBitmapEffect
Each bitmap effect has properties that can control the filtering properties, such as Radius of BlurBitmapEffect.

11. What is value converter in WPF?

Answer: A value converter acts as a bridge between a target and a source and it is necessary when a target is bound with one source, for instance you have a text box and a button control. You want to enable or disable the button control when the text of the text box is filled or null. In this case you need to convert the string data to Boolean. This is possible using a Value Converter. To implement Value Converters, there is the requirement to inherit from I Value Converter in the System.Windows.Data namespace and implement the two methods Convert and Convert Back.

12. What Are The Ways You Can Declare Objects In Xaml?

Answer :

To declare objects in XAML, there are three ways:

Directly, using object element syntax: This syntax is used to declare root objects or nested objects that set property values
Indirectly by using attribute syntax: This syntax uses an inline string value which has an instruction on how to create an object. To set the value of the property to a newly created reference, the XAML parser uses this string
Using a markup extension.

13. Explain What Is Markup Extension In Xaml?

Answer :

Markup extensions are placeholders in XAML that are used to resolve property at runtime. A markup extension allows you to extend XAML and using attribute syntax you can also set any property that can be set in XAML.The purpose of the mark up extension is to process a string and return an object. Some of the standard markup extensions are xNull, x: Array, :StaticResource and DynamicResource.

14. How To Get Automation Ids Of Items In A Itemscontrol?

Answer :

The best way to do this is by setting it Name property as it is utilized for automation purposes by default. But if you require to give an ID to an element, other than it’s name, then the AutomationProperties.AutomationID property can be set as per need.

15. How Can Listbox Be Made To Scroll Smoothly?

Answer :

ListBox is configured to scroll on an item-by-item basis by default. This is dependent on the height of each element and the scrolling action, thus, giving a rough feeling. Better way is to configure scrolling action so that it shifts items by a few pixels irrespective of their height. This is done by setting the ScrollViewer.CanContentScroll property to “false”. This will, however, make the ListBox lose the virtualization property. (Latest 50 WPF Interview Questions And Answers Pdf)

16. What does Polyline stand for in WPF?

Answer: In AutoCAD, Polyline is an object, which consists of one or more than one line or arc in segments. To define it, a polyline is a collection of connected straight lines. The Polyline object represents a polyline shape and draws a polyline with the given points. The Points property represents the points in a polyline. The Stroke property sets the color and StrokeThickness represents the width of the line of a polyline.

17. What do you understand by WPF AccessText Control?

Answer: 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!

18. What is a content control in WPF?

Answer:
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.

19. What is MVVM?

Answer: MVVM is stand for Model View ViewModel. It is a framework for making applications in WPF. MVVM is the same as the MVC framework. It is a 3-tier architecture plus one more layer. Loose coupling can be attained by using MVVM.

20. What is Dependency Property in WPF ?

Answer: 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. (Latest 50 WPF Interview Questions And Answers Pdf)

21. What is Attached Properties in WPF ?

Answer: Attached properties are basically Dependency Properties that allows the attachment of a value to any random object. Attached Properties (AP) are again a kind of Dependency Property (DP) in XAML. They can be used to receive a notification of a change of themself 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.

The type that defines the Attached Property is designed so that it can be the parent element of the elements that will set values for the Attached Property. The type then iterates its child objects using internal logic against some object’s tree structure, obtains the values and acts on those values in some manner.

The type that defines the Attached Property will be used as the child element for a variety of possible parent elements and content models. (C# Developer Interview Questions And Answers)

The type that defines the Attached Property represents a service. Other types set values for the Attached Property. Then, when the element that set the property is evaluated in the context of the service, the Attached Property values are obtained using internal logic of the service class.
APs are called “attached” properties because we can attach some behaviour to the control that is originally not expected from that control.

22. What is value convertor in WPF?

Answer: A Value Converter functions as a bridge between a target and a source and it is necessary when a target is bound with one source, for instance you have a text box and a button control. You want to enable or disable the button control when the text of the text box is filled or null.
In this case you need to convert the string data to Boolean. This is possible using a Value Converter. To implement Value Converters, there is the requirement to inherit from I Value Converter in the System.Windows.Data namespace and implement the two methods Convert and Convert Back.

Note: In WPF, Binding helps to flow the 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.

Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
namespace ValueConverters

23. What are the Templates in WPF ?

Answer: Templates are an integral part of user interface design in WPF. WPF has the following three types of templates:

  • Control Template
  • Items Panel Template
  • Data Template
  • Control Template

The ControlTemplate of a control defines the appearance of the control. We can change or define a new look and appearance of a control by simply changing the ControlTemplate of a control. ControlTemplates are even more useful when you write your own controls. Using ControlTemplates, you can build a custom button that has a circular layout and changes its color when you mouse over or press it.

24.How can you validate the value of DependencyProperty?

Answer: DependencyProperty declaration takes a ValidateValueCallback object. In the object we can define a callback function which execute whenever DependencyProperty changed. Callback function returns bool value if true new value is valid else invalid value. (C Sharp DotNet Online Training)

25. What is Style in WPF ?

Answer: 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).

26.What is XAML in WPF and why do we need it?

Answer: XAML is a XML file which represents your WPF UI. The whole point of creating the UI representation in XML was write once and run it anywhere. So the same XAML UI can be rendered as windows application with WPF and the same UI can be displayed on the browser using WPF browser or Silverlight application.

27. What are the dependency properties?

Answer: Dependency properties are the type of properties which belong to a specific class but can be used for another class. (Latest 50 WPF Interview Questions And Answers Pdf)

28. What is the difference between Silverlight and WPF browser application?

Answer:
These are the main differences between the Silverlight and WPF browser application:

.NET framework is needed for running WPF browser application on the client machine while Silverlight runs using only plug-in.
The applications made in WPF depend on the operating system because .NET framework only runs on Windows. On the other hand, Silverlight plug-ins can be installed on those OS also, which are not Windows. (Dot Net Training Online)

29. What are the most important features of MVVM?

Answer:
A list of most important features of MVVM:

MVVM separates the business and presentation layers, like MVP and MVC.
It improves Structure/separation of concerns (View, ViewModel and Model).
It enables a better Design/Developer Workflow.
It improves simplicity and testability.
It is enabled by the robust data binding capability of XAML.
No need to use a code behind file (minimalist code-behind file).
Provides application development ability for multiple environments.
Powerful Data Binding, command, validation and much more.
The designer and developer can work together.

30. What Is Xaml Namespace?

Answer :

Namespace can be defined as an environment or an abstract container used to hold a logical grouping of unique identifiers or symbols.

31. What is the difference between Page control and Window Control in WPF?

Answer:
No.
Page controls
Window controls
1. Page controls preside over the hosted browsers applications.
Window controls preside over windows application.
2. Page controls cannot contain window control.
Window controls may contain page control.

32. Explain How You Can Display Different Data At Run Time And Design Time?

Answer :

One way of displaying data at run time and design time is to declare your data in XAML.
Another way of doing it is by declaring it in XAML by using various data attributes from the designer XML namespace. With a d: prefix, this namespace is typically declared.

33. Explain What Is Type Converter?

Answer :

The type converter is helpful to convert a string into the appropriate value type where there is no markup extension usage. Type Converter defines four members for converting to and from string for xaml purposes.

CanConvertTo
CanConvertFrom
ConvertTo
ConvertFrom (Latest 50 WPF Interview Questions And Answers Pdf)

34. Why Is It Better To Wrap Items In Combobox Item?

Answer :

It has some important properties like IsSelected and IsHighlighted and also some necessary events like Selected and Unselected. ComboBoxItem is a content control and is thus very useful for adding simple strings to a ComboBox.(Informatica Training Videos)

35. Can Windows Service Be Created Using Wpf?

Answer :

No, Windows Services cannot be created using WPF. WPF is a presentation language. Windows services need specific permissions to execute some GUI related functions. Therefore, if it does not get the required permissions, it gives errors.

36. What Is An Adorner?

Answer :

They are a special kind of FrameworkElement that provide visual clues to the user. They are also used to add handles to elements and give information about the state of a control. Adorners are bound to the UIElement and are rendered on a surface that lies above the element, which is adorned. This surface is called an AdornerLayer. Adorners are mostly placed relatively to the bounded element.

37. How is Silverlight different from WPF browser application?

Answer :

One of the major differences is that .NET framework is required for running WPF browser applications on the client machine. But Silverlight runs using only the plug-in. Another point of difference is that applications made in WPF depend on the OS as .NET Framework only runs on Windows. On the other hand, the Silverlight plug-in can be installed on those OSs also, which are not Windows.

38. What is the value converter in WPF?

Answer: 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.

39. What is a Prism in WPF?

Answer: Prism is also known as Composite Application Guidance for WPF and Silverlight. It is a framework that can be used to build Silverlight apps and WPF. It has been designed to build solid applications in Silverlight and WPF that normally have a single code base. It is helpful in developing a client application, which is in a modular fashion. It is done so to divide large, complex applications into simple modules. The actual definition of a Prism being “Prism is developed by Microsoft Patterns and Practices and provides guidance designed to help you to more easily design and build rich, flexible and easy-to-maintain Windows Presentation Foundation (WPF) desktop applications.” it was initially called Prism but later on Microsoft named it as ‘CompositeWPF’.

40. What is WPF TextBlock?

Answer: In WPF, one of the most fundamental controls is the TextBlock control that comes in very handy. It is used to put text on the screen, very much like using the Label control, but in a much less resource demanding and simpler way. Both the TextBlock and Label, offer their unique advantages, so the situation demands what you may use at one particular time. (Latest 50 WPF Interview Questions And Answers Pdf)

41. What is Prism in WPF?

Answer: Prism (Composite Application Guidance for WPF and Silverlight) is designed to build applications in WPF and Silverlight that have a single code base. It helps to develop the client application in a modular fashion so that complexity of a large application can be divided into simpler modules.

In other words “Prism is developed by Microsoft Patterns and Practices and provides guidance designed to help you to more easily design and build rich, flexible and easy-to-maintain Windows Presentation Foundation (WPF) desktop applications.”.

Architecture: The following diagram shows basic architecture:

Architecture

App.XAML: Call Boot Strapper on Application_Startup.
BootStrapper: This is a class file that calls Shell (Shell.XAML) and so creates catalogue of module.
Shell: This is like a Master Page having regions.
Region: It is like placeholders to register views.
View: This is XAML file having User Interface
Module: Each module can have one or more View(s) which are registered to Region (in the Shell) through Region Manager.
See for more details:

Introduction to Prism – Composite Application Library (CAL) for WPF and Silverlight

42. What is the difference between MVP, MVC and MVVM?

Answer:

MVP (Model-View-Presenter)

In the MVP pattern the User sends the input to the view, the view forward it to presenter and presenter then modify the view or the model depending on the type of user action. The view and the presenter are tightly coupled through bi-directional relationship. The model does not know about the presenter. The view itself is passive, thats why it’s called presenter pattern, since the presenter pushes the data into the view.

MVP pattern

MVC (Model-View-Controller)

In this pattern there is only one controller that gets all the inputs directly, it modifies the data in the model depending upon the type of the input. Both the model and the view are created by the controller. The view only knows about the model, but the model does not know about any other objects.

MVP

The Model View ViewModel (MVVM) is an architectural pattern used in software engineering that originated from Microsoft which is specialized in the Presentation Model design pattern. It is based on the Model-view-controller pattern (MVC), MVVM is a way of creating client applications that leverages core features of the WPF platform, allows for simple unit testing of application functionality, and helps developers and designers work together with less technical difficulties.

43. What is the difference between Static and Dynamic resources?

Answer:

The most basic difference is that StaticResource evaluates the resource one time only, but DynamicResource evaluates it every time the resource is required. And due to this reason, DyanamicResource is heavy on the system but it makes pages or windows load faster.

Static Resources

A Static Resource will be resolved and assigned to the property during the loading of the XAML that occurs before the application is actually run. It will only be assigned once and any changes to the resource dictionary is ignored.

Static resource references work best for the following circumstances:

Your application design concentrates most of its resources into page or application level resource dictionaries. Static resource references are not re-evaluated based on runtime behaviours such as reloading a page, and therefore there can be some performance benefit to avoiding large numbers of dynamic resource references when they are not necessary per your resource and application design.

You are setting the value of a property that is not on a Dependency Object or a freezable.

You are creating a resource dictionary that will be compiled into a DLL, and packaged as part of the application or shared between applications.
Dynamic Resources

A Dynamic Resource assigns an Expression object to the property during loading but does not actually lookup the resource until runtime when the Expression object is asked for the value. This defers looking up the resource until it is needed at runtime.

Dynamic resources work best for the following circumstances:

The value of the resource depends on conditions that are not known until runtime. This includes system resources, or resources that are otherwise user settable. For example, you can create setter values that refer to system properties, as exposed by System Colours, System Fonts, or System Parameters. These values are truly dynamic because they ultimately come from the runtime environment of the user and operating system. You might also have application-level themes that can change, where page-level resource access must also capture the change.

You are creating or referencing theme styles for a custom control. (Latest 50 WPF Interview Questions And Answers Pdf)

44. What is Converter in WPF ?

Answer: 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.

45. What are the capabilities of WPF?

Answer: WPF has following capabilities:

It has all the equivalent common user controls like buttons, checkboxes, sliders etc.
It has all the capabilities of HTML and Flash.
It supports fix and flow format document.
It provides the facility of data binding, animation and multimedia.

46. What are the freezable objects in WPF?

Answer: An object which is unchangeable is known as freezable object. The freezable objects perform better and also safer if they are required to be shared between threads.

47. What is the meaning of BAML in WPF?

Answer: BAML stands for Binary Application Markup Language. It is a type of XAML that has been tokenized, parsed, and changed into binary form.

48. How Custom Classes Used In Xaml Can Be Defined?

Answer :

Custom classes are used in two ways:

With the code that produces the Primary Windows Presentation Foundation (WPF) application or within the code behind.
In a separate assembly as a class, such as an executable or DLL used as a class library.

49. Where Does The Execution Start In A Wpf Application?

Answer :

WPF applications created in Visual Studio run without a Main method. This is because the applications are special-cased when they are compiled from XAML. That means, Visual Studio attaches a Build Action of ApplicationDefinition to the XAML file. This results in the auto generation of a Main method.

50. What Is Xbap?

Answer :

XBAP is the abbreviated form of XAML Browser Application. It allows WPF applications to run inside web browsers. Installation of .NET framework on the client machine is a prerequisite for running WPF applications. But hosted applications are not given full admission to the client’s machine and are executed in a sandbox environment. Using WPF, such applications can also be created, which run directly in the browser. These applications are called XBAP.

Latest 50 WPF Interview Questions And Answers Pdf was last modified: September 1st, 2018 by Raghu ram

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.