WPF Interview Questions and Answers (2026)
WPF interviews tend to focus on whether you actually understand MVVM and the property/binding system that makes it work, rather than just XAML syntax. Here are the WPF questions that come up most often, covering dependency properties, commands, templates, and the UI thread.
-
What is MVVM and why is it the standard pattern for WPF apps?
MVVM (Model-View-ViewModel) separates a UI's presentation logic from its visual definition: the Model holds domain data/business logic, the View is the XAML defining UI structure with no code-behind logic, and the ViewModel exposes data and commands the View binds to, translating Model state into something bindable and handling user actions. WPF's data binding engine,
INotifyPropertyChanged, andICommandwere essentially designed to make MVVM natural — the View declaratively binds to ViewModel properties/commands via XAML without needing to know concrete types, which keeps UI logic testable (ViewModels can be unit tested without a rendered UI) and lets designers and developers work on XAML and logic somewhat independently. It also avoids the tightly-coupled, hard-to-test code-behind spaghetti common in earlier WinForms-style development. -
What's the difference between a dependency property and a regular CLR property?
A dependency property is registered with WPF's property system via
DependencyProperty.Registerand backed by an efficient internal storage mechanism rather than a simple field, which unlocks WPF features a plain CLR property can't participate in: data binding, styling, animation, resource references, value inheritance from parent elements, and automatic change notification without manually implementingINotifyPropertyChanged. Dependency properties also support a value-resolution precedence system (local value > style trigger > template > inherited > default), which is how the same property can be set by animation, style, and code all at once with well-defined winner rules. A regular CLR property is just a normal getter/setter over a field, cheaper to declare, but invisible to the WPF property engine unless you manually wire up notification.public static readonly DependencyProperty ValueProperty = DependencyProperty.Register(nameof(Value), typeof(int), typeof(MyControl)); public int Value { get => (int)GetValue(ValueProperty); set => SetValue(ValueProperty, value); } -
What are the data binding modes in WPF, and when do you use each?
OneWaypushes source-to-target only, updating the UI when the ViewModel changes but not writing back user edits — good for read-only display like labels.TwoWaysynchronizes both directions — the default for editable input controls likeTextBox.Text— so UI edits update the ViewModel and vice versa.OneWayToSourcepushes target-to-source only, rarely used, useful when you want a control's state to update a ViewModel but never be overwritten by it.OneTimereads the source once at binding creation and never updates again in either direction, useful for static/startup-only values to reduce binding overhead.Defaultuses the binding mode metadata defined by the target property's dependency property (e.g.,TextBox.Textdefaults toTwoWay,TextBlock.Textdefaults toOneWay). -
What are routed events, and what's the difference between bubbling and tunneling?
Routed events travel through the visual tree rather than firing only on the exact element that raised them, letting a parent handle events raised deep inside its child content without wiring up a handler on every element. Bubbling events (like
Click, most...Click/...Changedevents) start at the source element and travel up through ancestors to the root — useful for a container to intercept/handle interactions from any descendant. Tunneling events (prefixedPreview..., likePreviewMouseDown) start at the root and travel down to the source before the corresponding bubbling event fires, letting ancestors intercept and potentially suppress an event (e.Handled = true) before it reaches the target. This tunnel-then-bubble pairing (e.g.,PreviewKeyDownthenKeyDown) is a distinctive WPF input-handling design. -
What are the basics of XAML you should understand?
XAML (Extensible Application Markup Language) is a declarative XML-based syntax for constructing object trees — each element maps to a .NET type instantiation, and attributes map to properties or events, with the XAML compiler generating equivalent C# object-construction code (via
InitializeComponent()) at build time. Property element syntax (<Button.Background>...</Button.Background>) is used when a value is too complex for a simple attribute string. Markup extensions ({Binding Path},{StaticResource Key},{x:Static}) provide special non-literal value assignment.x:Namegives an element a code-behind-accessible identifier, distinct from the runtimeNameproperty. Namespaces (xmlns) map XML prefixes to CLR namespaces/assemblies, letting you reference custom controls alongside built-in WPF types in the same markup. -
What is `ICommand`, and how does a typical RelayCommand implementation work?
ICommandis the interface WPF's command-binding infrastructure (e.g.,Button.Command) expects, exposingExecute(object parameter),CanExecute(object parameter), and aCanExecuteChangedevent that WPF listens to in order to automatically enable/disable bound controls. Since implementing a new class for every command is tedious, aRelayCommand(orDelegateCommand) is a reusable generic implementation that wraps two delegates — anActionforExecuteand aFunc<bool>forCanExecute— passed in via constructor, letting ViewModels expose commands as simple properties without command-specific boilerplate classes. This lets Views bind buttons directly to ViewModel behavior (Command="{Binding SaveCommand}") instead of handlingClickevents in code-behind, which is central to keeping MVVM code-behind-free.public class RelayCommand : ICommand { private readonly Action _execute; private readonly Func<bool>? _canExecute; public RelayCommand(Action execute, Func<bool>? canExecute = null) { _execute = execute; _canExecute = canExecute; } public bool CanExecute(object? p) => _canExecute?.Invoke() ?? true; public void Execute(object? p) => _execute(); public event EventHandler? CanExecuteChanged { add => CommandManager.RequerySuggested += value; remove => CommandManager.RequerySuggested -= value; } } -
How do `ItemsControl` and `DataTemplate` work together?
ItemsControl(and its subclassesListBox,ListView,ComboBox,ItemsControlitself) binds to a collection viaItemsSourceand generates a visual element for each item, but by default just callsToString()unless you supply aDataTemplatedescribing how each data object should actually be rendered. TheDataTemplateis XAML that gets instantiated once per item, with its root'sDataContextimplicitly set to that item — so bindings inside the template reference properties on the individual item, not the parent ViewModel. This cleanly separates "what data to show" (ViewModel's collection) from "how to visually represent one item" (DataTemplate), and templates can be selected dynamically per item type usingDataTemplateSelectoror implicit typedDataTemplates keyed byDataType. -
What is the UI thread and `Dispatcher`, and why does it matter?
WPF UI elements are single-threaded-apartment objects that can only be created and accessed from the thread that created them — normally one dedicated UI thread per application, running a message loop (the
Dispatcher) that processes input, layout, and rendering work as prioritized queued operations. Attempting to touch a UI element from a background thread (e.g., updating aTextBlockfrom aTask.Runcallback or a non-UI async continuation) throws anInvalidOperationException. To safely update UI from another thread, you marshal the call back viaDispatcher.Invoke/InvokeAsync, or rely onasync/await's default behavior of resuming continuations on the capturedSynchronizationContext, which for WPF is dispatcher-based and automatically returns you to the UI thread after an awaited background operation.Application.Current.Dispatcher.Invoke(() => statusLabel.Text = "Done"); -
What's the difference between styles and templates in WPF?
A
Stylesets property values (and can attach triggers/event setters) on an existing control without changing its visual structure — e.g., settingBackground,FontSize, andMarginconsistently across allButtons of a certain type, similar in spirit to CSS. AControlTemplatecompletely replaces a control's visual tree/rendering structure while preserving its behavior and API — e.g., redefining what aButtonactually looks like (shape, layout of its parts) while it still functions as a clickable button responding to the same commands and events. ADataTemplate(related but distinct) defines how to visually represent a piece of *data*, not a control. In short: Style = "how existing visuals are styled," Template = "what the visual structure itself is." -
What are resource dictionaries, and how does resource lookup work?
A
ResourceDictionaryis a keyed collection of reusable objects — brushes, styles, templates, converters — declared once in XAML and referenced elsewhere via{StaticResource Key}(resolved once at load time) or{DynamicResource Key}(resolved lazily and re-resolved if the resource changes, at a small performance cost). Resources can be scoped at the element level (<Grid.Resources>), Window/UserControl level, or merged at the Application level viaApp.xaml'sMergedDictionaries, and lookup walks up the visual/logical tree from the requesting element to the nearest matching key, falling back to Application-level resources last. This enables centralizing a design system's colors, styles, and templates in shared dictionaries that multiple views merge in, keeping visual consistency without duplicating markup. -
What is `INotifyPropertyChanged`, and why is it essential in MVVM?
INotifyPropertyChangedis a single-method interface (event PropertyChangedEventHandler PropertyChanged) that a bindable ViewModel implements so WPF's binding engine knows when a property value changed and needs to refresh the UI. Without raising this event on every property setter,OneWay/TwoWaybindings would only pick up the value present at binding time and never update afterward as the ViewModel's data changes programmatically. The convention is to raise it inside each property setter, typically via a shared helper to avoid repeating boilerplate, passing the changed property's name (often via[CallerMemberName]to avoid magic strings). Most ViewModel base classes provide a reusableSetPropertyhelper for exactly this purpose.private string _name; public string Name { get => _name; set { _name = value; OnPropertyChanged(); } // raises PropertyChanged(nameof(Name)) } -
What are attached properties, and what's a canonical use case?
An attached property is a special kind of dependency property that can be set on *any*
DependencyObject, not just the type that defines it, using the syntax<Element OwnerType.PropertyName="value" />. It's registered viaDependencyProperty.RegisterAttachedand lets a parent-oriented concept "attach" metadata to arbitrary children — the canonical example isGrid.Row/Grid.Column, whereGriddefines the property but any child element placed inside aGridcan set it to declare its own cell position, even thoughGrid.Rowhas nothing to do with the child element's own type. Other common examples includeCanvas.Left/Top,DockPanel.Dock, andPanel.ZIndex. Attached properties are also frequently used to add MVVM-friendly "attached behaviors" to controls that don't natively expose the hook you need (e.g., binding a command to a non-command event).
Practicing for a real interview? Get live AI help with your answers, in the browser, free to start.
Start a free session