Back
Decor-dark

75+ Best WPF Interview Questions To Hire Or Get Hired With

4757 words Read time 23:53

WPF or Windows Presentation Foundation is a tool for rendering graphical user interfaces. It was previously known as "Avalon" but later changed to WPF. The tool is a core part of C++ and C# developers. This tool would be used for developers who are attempting to make native applications for Windows or Microsoft machines. Below are WPF interview questions and answers for those who are beginners and those who are already advanced users. It is a helpful guide to study before you go into your technical job interview. As with everything I do that relates to interview questions, these are mock answers. It is best if you put together your own set of answers and benchmark them against the following.

1. What is WPF?

WPF is the abbreviation for Windows Presentation Foundation. It is a re-invention of a UI for desktop applications using WPF, besides dropping controls on Windows forms the same way developers have been doing for years. WPF is recommendable because it provides extra rapid boost application development including Rich User interface, animation and much more.

2. Highlight some of the uses of WPF.

• Draw normal controls and graphics.
• Can easily load/play audio and video files.
• Can provide smooth graphical effects such as drop shadows and color gradients.
• Can use shared styles which can be used across the same controls to provide the same theme, skin and design.
• Transforming objects including shapes, controls and video.
• Can create and animate 3D graphics.
• Can easily draw vector graphics that scale without jagged aliasing.

3. List the advantages of using WPF.

• Tight multimedia integration
• Resolution independence
• Hardware acceleration

4. What are the features of WPF?

• Visual State Manager
• Touch and Manipulation
• Graphics and Animations
• Binding
• XAML Browser Applications
• Silverlight Designer

5. What type of documents are supported by WPF.

The documents supported by WPF are Flow format and Fixed format document. The flow format document alters the content to fit the screen size while the fixed format document present content irrespective of the screen size.

6. What namespace is required for working with 3D?

The namespace is System.Windows.Media.Medi3D.

7. Is it correct to say that WPF has replaced DirectX?

WPF cannot be said to have replaced Direct because it can’t be used to create games with stunning graphics. WPF is was developed with the objective of replacing Windows for and not DirectX.

8. Define dependency properties.

These are properties that belong to a specific class but can be used for another class

9. Explain how you can increase the size of status bar proportionally.

This can be done by overruling the ItemPanel attributes of the Status bar with a grid. The grid columns can be appropriately configured to get the desired result.

10. Define freezable objects in WPF.

These are objects that have their state locked down making it appear unchangeable. These objects perform better. They are also safer if they are required to be shared between threads.

11. Define content alignment in WPF.

There are different ways that programmer deal with content of content controls on WPF. The popular properties are HorizontalContentAlignment and VerticalContentAlignment.

Both properties are defined in the System.Windows.Controls.Control class that is the parent class of all controls in WPF.

The programmers do content alignment by creating a UI with a Button and a TextBox control, the UI will appear to have a default vertical and horizontal alignment of content of a button in the center.

The default vertical and horizontal alignment of content of a text box I felt and top.

To set the contents of the Button and Textbox to bottom right the developer will need to the codes.

VerticalContentAlignment and HorizontalContentAlignmentproperties

Below is a syntax that can be used for this purpose:

1. <Grid Name="StackPanel1" Background="LightGray">

2. <Button Name="Button1" Background="LightBlue" Height="45" Content="Click Me!" Margin="23,12,159,0" VerticalAlignment="Top" FontSize="16" FontWeight="Bold" VerticalContentAlignment="Bottom" HorizontalContentAlignment="Right" />

3. <TextBox Height="50" Margin="26,72,74,0" Name="textBox1" VerticalAlignment="Top" Text="I am a TextBox" FontSize="16" VerticalContentAlignment="Bottom" HorizontalContentAlignment="Right" />

4. </Grid>

12. Name the class used for converting the instances of string to and for instances of Brush.

BrushValueSerializer class.

13. Describe the advantages of using WPF over Winforms.

• WPF is a newer version with fine tune in current standards while Winforms is an older version bit is it is more tried and tested.
• WPF is build form scratch and doesn’t rely on standard windows controls in almost all situations. Winforms is a simply a layer on tops of the standard windows controls (Eg. A textbox).
• It utilizes a lot of new applications such as visual studio. The Winforms application uses existed 3rd party controls that can be bought or accessed for free.
• It is more flexible in Winforms the designer in Visual Studio is still, as of writing.
• It can do more things without having to write if buy new controls. However, it is better for Winforms than for WPF, where you will have to do more of the work yourself with WPF.
• When you do need to use 3rd party controls, the developers of these controls will likely be more focused on WPF because it's newer. Winforms on the other hand Uses existed 3rd party control.
• XAML makes it easy to create and edit your GUI, and allows the work to be split between a designer (XAML) and a programmer (C#, VB.NET etc.). It is also possible to use XAML to design the Windows Forms project forms. But the programmer will need to deserialize the classes in the namespace System.Windows.Forms.
• Other advantages of WPF are that Databinding, which allows you to get a more clean separation of data and layout.
• And lastly WPF allows you to make user interfaces for both Windows applications and web applications (Silverlight/XBAP).

15. Describe resources in WPF.

WPF is recommendable because it provides a simplified way of reusing commonly defined objects and values. The resources in WPF allow developers to set properties of multiple controls at a time. For instance the developer 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.

The method of accessing resources is:

<elementName propertyName="{markupExtension keyName}">
Content
</elementName>

• elementName: Name of the element that uses the resource.
• propertyName: Name of the property that takes its value from the resource.
• markupExtension: Define type of resource.
• keyName: key name of the resource, which is unique string to identify the resource.

16. List two types of resources in WPF.

There are two types of resource, namely:

• Static Resource
• Dynamic Resource

17. Define static resources in WPF.

The StaticResource markup extension is usually used to define the resource as a static resource. The value of StaticResource is determined at the time of loading.

Add the below code snippet in Window1.xaml file inside the Grid.

1. <Grid.Resources>
2. <SolidColorBrush x:Key="lblbgcolor" Color="Blue"/>
3. </Grid.Resources>
4. <Label Name="lbl" Margin="71,44,77,0" Background="{StaticResourcelblbgcolor}" Height="49" />

Above code, Grid control uses the Resources property (<Grid.Resources>) to define resource. SolidColorBrush resource named lblbgcolor defined. lblbgcolor resource is used to set the background property of label.

18. Describe Dynamic Resource.

Dynamic Resource is used when the developer wants to change the value of property at run time.

In the sample program, add the following code snippet in Window1.xaml file inside the Window element.

1. <Window.Resources>
2. <SolidColorBrush x:Key="brush" Color="Red" />
3. </Window.Resources>
4. <Button x:Name="btn" Content="Click Me" Click="Button_Click" Background="{DynamicResource brush}" Height="100" Width="100" />

Open code behind and add the following code snippet.

1. private void Button_Click(object sender, RoutedEventArgs e)
2. {
3. this.btn.SetResourceReference(BackgroundProperty, "brush");
4. }
In the above code, Window control uses the Resources property () to define resource. SolidColorBrush resource named brush defined. Brush resource is used to set the background property of button.

19. Describe value convertor in WPF?.

The value convertor functions as a bridge between a target and a source. This function is necessary when a target is built with one source for instance when you have a text box a button control. If you intend to enable or disable the button control when the text to the textbox is filled or null. To successfully achieve the value converting function a programmer might need to convert the string data to Boolean which is possible through value convertor. In order to implement value convertors, the programmer will need to inherit from I Value Converter in the System.Windows.Data namespace and implement the two methods Convertand Convert Back.

The syntax below illustrates how value convertor function can be implemented:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
namespace ValueConverters
{
public class ValueConverter: IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
bool isenable = true;
if (string.IsNullOrEmpty(value.ToString()))
{
isenable = false;
}
return isenable;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

20. Explain the advantages of using WPF over adobe flash.

WPF is modern development and therefore utilizes re-invented technology. Therefore has latest development tools. WPF also supports a broader range of programming languages and has a robust control reuse.

21. Explain how Silverlight differs from WPF browser application.

Typically running the WPF browser application requires .NET framework to be activated in the client machine. In Silverlight only plugins are required to run it. Applications that are associated with WPF depend on the OS as .NET Framework only runs on Windows. On the other hand, Silverlight plugin can be installed on the Oss that are not Windows.

22. Explain the methods available in DependencyObject.

• SetValue
• ClearValue
• GetValue

23. Define PRISM

This a framework used for developing complex applications for WPF, Silverlight or Windows Phone. The framework utilizes MVVM, Command patterns, DI and Separation of Concerns to get loose coupling.

24. Define MVVN

MVVM is an acronym for model view viewmodel and a framework used for making applications in WPF. It is similar to MVC framework. Technically, it is a 3-tier architecture plus one more layer. It is possible to loose coupling using MVVM. The framework was introduced by John Gossman in 2005 for use with WPF as a concrete application of Martin Fowler's broader Presentation Model pattern. Applications such as Microsoft Expression products among other commercial applicatiosn has been developed using MVVM.

25. What are the advantages of using MVVM?

• Modularity.
• Test driven approach.
• Separation UI and Business layer as view and view model.
• Code sharing between pages and forms.
• Easy to Maintain.

26. What are the features of MVVM?

• It separates the business and presentation layers, like MVP and MVC. • Improve Structure/separation of concerns (View, ViewModel and Model).
• Enable a better Design/Developer Workflow.
• Enhance simplicity and testability.
• 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.

27. Explain the view and view model in MVVM.

The View is the client interface, input-output interface or the user interface. The view collects all the user interface elements of the window, navigation page, user control, resources file, style and themes, custom tools and controls. Typically the View is not aware of ViewModel and the model and vice versa because the control is highly decoupled. However the view model recognizes the need for View. The only communications between the two is through data binding and a dependency property or properties. The ViewModel on the other hand is a nonvisual class. The ViewModel is unaware of the view directly. However, models are connected directly to the ViewModel and invoke a method by model class. The ViewModel understands what the model has and is aware of what the view needs. A single ViewModel can connect with multiple models. A ViewModel inherits some interface like INotifyPropertyChanged, icommand INotifyCollectionChanged etcetera.

28. Define customControl.

This a tool used to expand the functions of the existing controls. It carries default style in Themes/Generic.xaml and a code file. Programmers usually use it to make a control library and can be styled or templated.

29. List major assemblies used in WPF.

• PresentationFoundation
• WindowsBase
• PresentaionCore

30. Describe Path animations in WPF.

• This is a type of animation in which the animated objects follow a path set by the Path geometry.

31. Is it possible to create WPF application without involving XAML.

• Yes it is possible because using XAML in WPF is just a choice.

32. List the types of Windows in WPF.

• Normal Window
• Page Window
• Navigate Window

33. Describe the use of WindowsBase assembly.

WindowsBase assembly carries the following items:

• DispatcherObject - Base class for all WPF types.
• DependencyObject - It's enables WPF property system services on its derived classes.
• DependencyProperty - It represents a property which can be set through Styles, Data Binding, Animation. It's inherit values from parent element and provides change notification.
• DispatcherTimer - A special timer class which Tick event method executes on Dispatcher Queue.

34. Define PresentaionCore assembly.

This is an assembly that provides visual class that contains all the visual controls in WPF that need to be inherited. The assembly interacts directly with MilCore Unmanaged assembly for rendering the visual system.

35. Describe PresentationFrameWork Assembly.

This assembly bears all the UI controls like TextBlock, Label, CheckBox, TextBox, ListView, DataGrid.

36. Describe the MilCore Assembly.

This an assembly that directly interacts with DirectX fr rendering the visual system of WPF. WPF uses DirectX for rendering their display. DirectX is used for efficient hardware and software rendering.

37. Define WindowsCodec assembly.

This assembly is used to display images in WPF. All imaging display, scaling, transforming is done by WindowsCodec assembly.

38. Define XAML.

This is an XML based language used fr developeign the WPF UI. The XAML elements are direct mapping for .Net Objects. A XAML element name is a .NET class name and XAML element property is the property of that .NET class.

39. Is XAML after compilation convert into Assembly.

Yes. It is stored as BAML (Binary Application Markup Language) into the assembly.

40. Give the syntax for dependencyProperty.

public static DependencyProperty BackgroundProperty = DependencyProperty.Register("Background", typeof(string), typeof(Customer), new PropertyMetadata("red"), new ValidateValueCallback(ValidateBackgroundProperty));
public string Background
{
get
{
return GetValue(BackgroundProperty) as string;
}
set
{
SetValue(BackgroundProperty, value);
}
}
public static bool ValidateBackgroundProperty(object value)
{
if((string)value == "red" || (string)value == "green")
{
return true;
}
return false;
}

40. How can you give default value to the dependencyProperty.

The DependencyProperty declaration takes a PropertyMetadata object where we can provide the default value.

41. Define a attached property.

This is a unique type of dependencyProperty in which the property is declared in one class an used in another class. For instance you can declare AttachedProperty in class MyAttachedProperties and used it with TextBlock, Button, Label objects.

42. Give the Syntax for attached properties.

public static readonly DependencyProperty CountProperty = DependencyProperty.RegisterAttached("Count", typeof(int),
typeof(MainWindow));
public static int GetCount(DependencyObject obj)
{
return (int)obj.GetValue(CountProperty);
}
public static void SetCount(DependencyObject obj, int value)
{
obj.SetValue(CountProperty, value);
}

43. Explain the difference between Attach Property and DependencyProperty.

The difference is that Dependency property is always attached with ine calls on which it is defined whciel attach property can be attached with any other class.

44. Describe Command Design Pattern and ICommand in WPF.

The command patterns allow the programmer to decouple the request from an object that performs an action. In this regard, the command pattern represents an action as an object. The best option for a programmer to implement operations based on the user request it is the command pattern. The Icommand on the other hand is a core component of MVVM. The Icommand is mostly used to provide separation logic between a View and View model. XAML offers a way to bind your GUI event better by ICommand. ICommand requires the user to define two methods, bool CanExecute and void Execute.

45. List the members of the Command design pattern.

• Client
• Invoker
• Command
• Concrete Command
• Receiver

46. Describe BAML.

This is an acronym for Binary Application Markup Language., it is tokenized XAML in binary form and quicker than XAML.

47. Compare WPF and Xamarin.Forms.

• Control templates: WPF supports the concept of control template which provides the visualization instructions for a control (Button, ListBox, etc.). Xamarin.forms have a ControlTemplate type that is used for theming Page objects.
• XAML: WPF supports XAML while in Xamarin.forms the syntax is identical - the primary difference is the objects that are defined/created by the XAML graphs.
• Markup extensions: in WPF the programmer must derive form MArkupExtensionn- an abstract base class. In Xamarin.Forms that is replaced with an interface IMarkupExtension or IMarkupExtension which is more flexible.
• RelativeSource: in WOF the relative source allows the developer to bind to the visual elements defined in XAML while in XAMRIN forms the function can be achieved using {x:Reference} markup extension.
• Text property - RelativeSource bindings: in WPF Text={Binding RelativeSource={RelativeSource otherControl}, Path=Text} command is used while Xamarin.forms uses Text={Binding Source={x:Reference otherControl}, Path=Text}.
• Both applications completely supports MVVM.
• User controls: In WPF, UserControls are used to provide a section of UI which has associated behavior. While in Xamarin.forms developers uses ContentView for the same purpose. Both support binding and inclusion in XAML.
• Navigation: WPF includes a rarely used NavigationService which could be used to provide a "browser-like" navigation feature while Xamarin.Forms includes support for several forms of navigation.
• URL Navigation: WPF is a desktop-oriented technology and can accept command-line parameters to direct startup behavior. Xamarin.Forms on the other hand has the capability to use deep URL linking to jump to a page on startup.

48. Give the path of selecting DatePicker.

Inheritance Object --> DispatcherObject --> DependencyObject --> Visual --> UIElement --> FrameworkElement --> Control --> DatePicker.

49. Describe the purpose of TreeView class in WPF.

TreeView presents the hierarchical collection of labeled items, each of those are indicated by a TreeNode.

50. Mention the main benefits of graphics in WPF

• Resolution-independent and device-independent graphics. • Improved precision
• Advanced graphics and animation support
• Hardware acceleration

51. Explain routed events in WPF.

A routed event is an event that can invoke handlers on more than one listeners present in an element tree. Other than a single object which is called the event this is known as the Routed event.

52. Name some layout panels available in WPF.

• Stack Panel
• Grid Panel
• Canvas Panel
• Dock Panel
• Wrap Panel

53. Name some major subsystems available in WPF.

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

54. Describe what is INotifyPropertyChanged Interface.

This is a function used to notify clients, especially those who are binding and mostly if the value of the property has been changed. The function has an event called PropeetyChanged which is constantly increased whenever a property of Model object is changed.

55. Name the method used to force a tool tip that is currently visible.

The tool tip can be closed by setting a tooltip’s isOpen property false function.

56. Why are layout patterns needed in WPF.

The panes are needed to ensure that controls fit the screens of different sizes or having different sizes. When controls are arranged on fixed pixel coordinates, then the model will fail when moved to a different environment. Therefore, the layout panels are essential in WPF.

57. Explain how you can determine if a freezable object is frozen.

The ‘IsFrozen’ property can be run to check if the freezable object is frozen.

58. Explain what unit of measurement is used in WPF.

Measurements in WPF are made in Device-independent pixels, or logical pixels. A pixel is equivalent to 1/96 part of an inch. The logical pixels are referred as double ad this makes them assume a fractional value.

59. Define Adorner.

This is a special kind of FrameworkElement which offers visual clues to the user. They are also used to add handles to elements and give information about the state of control .In WPF adorners are connected to UIElement and are rendered on a surface that occurs on the element. The surface is referred to as the AdronerLayer. The adorners are usually placed relatively to the bounded element.

60. Define serialization.

This is the process of converting the state of an object to stream of bytes.

61. Does WPF support MDI?

No MDI is not supported in WPF. UserControl can be used to give the same functionality as MDI.

62. Expain how you can make the ToolTip hover over a disabled element.

The ShowOnDisabled function can be utilized for purpose. The property belongs to ToolTipServces class.

63. Describe major types of routed events available in WPF

Direct - this a kind of event that is only raised by the element from which it originated form.
Tunneling - this event is raised by the element in which it was originated and then it gets raised by each consecutive container in the visual tree.
Bubbling - this event is raised by the uppermost container in the visual tree and then gets raised by each consecutive container lying below the uppermost on, till it reaches the element from which it originated.

64. Give the method used to retrieve the command-line arguments in a WPF application.

The popular methods for this function is s to call System.Environment.GetCommandLineArgs at any random point in the application.

65. List the classes that contain arbitrary content.

• Content Control
• HeaderedContent Control
• Items Control
• HeaderedItems Control

66. Give the namespace that contains ‘Popup’ and ‘Thumb’ controls.

The namespace that contains popup and thumbs is system.windows.controls.primitives

67. Explain how you can code to display Hello World in XAML.

Displaying “Hello World.”
<page xmlns= ‘’ ‘’>
<TextBlock>
Hello, World!
</TextBlock>
</Page>

68. How can you specify graphic components in WPF?

They are specified with open or closed tags with attributes. The syntax below is used for specifying graphic components:

<Button>
Click
</Button>

69. List four general kinds of XAML elements.

• Root Elements
• Panel Elements
• Control Elements
• Geometric Elements

70. What does X: prefix shows in XAML.

The X: prefix is used to map the XAML namespace in templates

71. Explain major kinds of X: prefix used in XAML language.

• x: Key: It sets a unique key for each resource in a Resource Dictionary.
• x: Class: It specifies the CLR ( Common Language Runtime) namespace and class name for the class that provides code.
• x: Name: It specifies a run-time object name for the instance that exist in run time code after an object element is processed.
• x: Static: It enables a reference that returns a static value which otherwise an XAML compatible property.
• x: Type: It constructs a Type reference based on the type name.

72. Name the types of children that object element supports in XAML.

• Collection Items
• A value for the content property
• The value that can be type-converted to the object element

73. Define type convertor.

This is is used in converting a string into the appropriate value type where there is no markup extension usage. Type convertor defines four members for converting to and fro string for XAML purposes:

• CanConvertTo
• CanConvertFrom
• ConvertTo
• ConvertFrom

74. Name the object element syntax in XAML.

To insatantiate a CLR class or structure by declaring an XML element, an XAML markup syntax is used. This syntax is referred as Object Element Syntax.

75. Describe how you can display different data at run time and design time?

• 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.

76. Explain how custom classes used in XAML can be defined?

• 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

Share this article

C

Reach out