Showing posts with label MVVM interview questions. Show all posts
Showing posts with label MVVM interview questions. Show all posts

Thursday, December 4, 2025

Top 20 WPF Interview Questions and Answers (With Detailed Explanations)

 

1. What is WPF?

Answer:
WPF (Windows Presentation Foundation) is a UI framework from Microsoft used for building desktop applications for Windows. It is part of the .NET ecosystem and uses XAML (Extensible Application Markup Language) to create rich user interfaces.

Key Features

  • Vector-based rendering

  • Hardware acceleration

  • Data binding

  • Styles & templates

  • Animation support

  • MVVM architecture compatibility


2. What is XAML in WPF?

Answer:
XAML stands for Extensible Application Markup Language. It is a declarative language used to design UI elements in WPF.

Advantages

  • Clear separation of UI and code-behind

  • Easy to maintain

  • Designer-friendly

  • Reduces code in .cs files


3. What is MVVM in WPF?

Answer:
MVVM (Model–View–ViewModel) is the most widely used architecture in WPF.

Components

  • Model: Business logic & data

  • View: XAML (UI)

  • ViewModel: Connects view and model using bindings

Benefits

  • Testability

  • Separation of concerns

  • Maintainability

  • Reusability of components


4. What is Data Binding in WPF?

Answer:
Data Binding connects UI elements to data sources such as objects, properties, and collections.

Binding Modes

  • OneWay

  • TwoWay

  • OneTime

  • OneWayToSource

Real-time Example

Binding a TextBox to a ViewModel property for editing user input.


5. What are Dependency Properties?

Answer:
A dependency property is a special type of property used by WPF to enable:

  • Data binding

  • Styles

  • Animation

  • Resources

Why Needed?

Normal CLR properties cannot support WPF’s advanced features.


6. What are Attached Properties?

Answer:
Attached properties are dependency properties used by parent containers to apply behavior to child elements.

**Example:

Grid.Row, Grid.Column**


7. What is a Routed Event in WPF?

Answer:
Routed events travel through the visual tree.

Types

  • Bubbling (child → parent)

  • Tunneling (parent → child)

  • Direct (control only)

Example

Button Click → bubbles up to Window.


8. What are Templates in WPF?

Answer:
Templates define how controls look.

Types

  • ControlTemplate: Changes visual structure

  • DataTemplate: Defines UI for data


9. What is the Difference Between StaticResource and DynamicResource?

StaticResourceDynamicResource
Loaded at compile timeLoaded at runtime
Faster performanceCan update UI dynamically
Cannot changeCan change

10. What are WPF Layout Panels?

Answer:
Panels arrange UI elements.

Common Layouts

  • Grid

  • StackPanel

  • WrapPanel

  • DockPanel

  • Canvas


11. What is ObservableCollection?

Answer:
A collection that notifies UI automatically when items are added, removed, or updated.

Used commonly in MVVM.


12. What is ICommand in WPF?

Answer:
ICommand allows binding buttons and UI actions to ViewModel methods.

Benefits

  • Removes code-behind

  • Improves MVVM structure


13. What is the Visual Tree in WPF?

Answer:
Visual Tree represents all visual elements of UI including controls and their internal templates.

Used for:

  • Rendering

  • Event routing

  • Template customization


14. What is Logical Tree in WPF?

Answer:
Logical tree contains high-level UI elements.

Example

Window → Grid → Button

Logical tree is simpler than the visual tree.


15. What are WPF Styles?

Answer:
Styles group common property values that can be applied to multiple controls.

Benefits

  • Reusability

  • Consistency

  • Easy maintenance


16. What is Value Converter (IValueConverter)?

Answer:
Converters help transform binding data.

Example

Convert boolean to visibility:

  • true → Visible

  • false → Collapsed


17. What is the Dispatcher in WPF?

Answer:
The Dispatcher manages the UI thread. WPF UI elements can be accessed only from the UI thread.

Usage

Dispatcher.Invoke(() => { ... });

18. What is the Difference Between WPF and WinForms?

WPFWinForms
Uses XAMLUses drag & drop designers
Hardware acceleratedGDI+ based
Supports MVVMNo built-in MVVM support
Better animations, graphicsLimited UI capabilities

19. What is Prism in WPF?

Answer:
Prism is a framework used for enterprise-level WPF applications.

Features

  • Dependency Injection

  • Navigation

  • Event Aggregator

  • Modular application support


20. How to Improve WPF Application Performance?

Key Tips

  • Use Virtualization

  • Freeze Freezable objects

  • Avoid complex layouts

  • Reduce data binding overhead

  • Enable async operations

  • Use BitmapCache for static UI

Don't Copy

Protected by Copyscape Online Plagiarism Checker

Pages