WPF interview questions and answers for desktop .NET developers

WPF interview questions check whether you can build a Windows desktop UI that stays responsive and testable: XAML and data binding, dependency properties, MVVM with commands, the Dispatcher and the UI thread, styles and templates, and list virtualization. Expect concept questions first, then a binding or threading bug to diagnose, then a scenario such as a screen that freezes while loading data. Answers that explain why the binding engine, the visual tree or the UI thread behaves the way it does score best.

By Published 10 min read

Where WPF questions show up

WPF (Windows Presentation Foundation) is still the UI stack behind many line-of-business desktop apps: trading and banking tools, hospital and lab software, manufacturing HMIs, CAD add-ins and internal admin consoles. Teams hiring for it usually want a C# developer who also understands the XAML side well enough to keep large screens fast and maintainable. Language questions about types, LINQ and async are covered in C# interview questions; this page stays on the desktop UI layer.

A typical loop starts with a screening call on C# and WPF basics, then a technical round where you read XAML and a view model and say why something does not update, then a practical task or pair session (build a small master-detail screen, add validation, make a long list scroll smoothly). Senior loops add design talk: how you split a large app into modules, how you test view models, and how you would move parts of it forward to newer .NET versions.

WPF fundamentals questions

First-round WPF questions for freshers and switchers
QuestionWhat it testsWhat a strong answer shows
What is XAML and how does it relate to the C# code-behind?Core modelXAML is a declarative way to build an object graph. It is compiled into BAML and loaded at run time; the code-behind is a partial class of the same type, joined by InitializeComponent.
Logical tree versus visual tree?Element modelThe logical tree is what you wrote (Window, Grid, Button). The visual tree adds every element templates create (Border, ContentPresenter, TextBlock). Resource lookup and routed events travel these trees.
Name the main layout panels and when you use each.LayoutGrid for rows and columns, StackPanel for a simple line, DockPanel for edges, WrapPanel for flowing items, Canvas only for absolute positions such as drawings.
How does layout work?Measure and arrangeA two-pass process: each element is asked how much space it wants (Measure), then given its final rectangle (Arrange). Deep nesting and auto sizing make both passes more expensive.
What are the binding modes?Data bindingOneWay, TwoWay, OneTime, OneWayToSource and Default. Default depends on the property: TextBox.Text is two-way, TextBlock.Text is one-way.
What is DataContext?Binding sourceThe default source for bindings, inherited down the element tree. Set it once on the view to the view model, and child bindings resolve against it.
What does UpdateSourceTrigger do?Binding timingIt controls when a two-way binding writes back. TextBox.Text defaults to LostFocus; PropertyChanged writes on every keystroke, which can be costly with heavy validation.
StaticResource versus DynamicResource?ResourcesStaticResource resolves once at load. DynamicResource keeps a reference and updates if the resource changes, which suits theme switching but costs more.
What are routed events?EventsEvents that travel the element tree: tunneling (Preview prefix, root to source), bubbling (source to root) and direct. Setting e.Handled = true stops the route for most handlers.
What is the difference between a Style and a ControlTemplate?StylingA Style sets property values on a control. A ControlTemplate replaces how the control looks, its whole visual tree, while keeping its behavior.
What is a DataTemplate?TemplatingIt describes how a data object is displayed, for example each item in a ListBox. A DataType on the template lets WPF pick it automatically.
First-round WPF questions for freshers and switchers. Scroll sideways on a small screen.

Intermediate: properties, binding and MVVM

Most WPF practical rounds hinge on one idea: the view binds to a view model, and the view model tells the view what changed. Interviewers often ask you to write the plumbing by hand before you mention a toolkit, so they can see you know what the toolkit generates. This version compiles with the old .NET Framework compiler as well as current .NET.

using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Input;

public abstract class ObservableObject : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

    protected bool Set<T>(ref T field, T value, [CallerMemberName] string name = null)
    {
        if (Equals(field, value)) return false;
        field = value;
        var handler = PropertyChanged;
        if (handler != null) handler(this, new PropertyChangedEventArgs(name));
        return true;
    }
}

public sealed class RelayCommand : ICommand
{
    private readonly Action _run;
    private readonly Func<bool> _canRun;

    public RelayCommand(Action run, Func<bool> canRun)
    {
        _run = run;
        _canRun = canRun;
    }

    public event EventHandler CanExecuteChanged;
    public bool CanExecute(object parameter) { return _canRun(); }
    public void Execute(object parameter) { _run(); }

    public void RaiseCanExecuteChanged()
    {
        var handler = CanExecuteChanged;
        if (handler != null) handler(this, EventArgs.Empty);
    }
}

public sealed class OrderViewModel : ObservableObject
{
    private string _customer = "";
    public RelayCommand SaveCommand { get; private set; }

    public OrderViewModel()
    {
        SaveCommand = new RelayCommand(
            () => Console.WriteLine("Saved order for " + Customer),
            () => Customer.Trim().Length > 0);
    }

    public string Customer
    {
        get { return _customer; }
        set { if (Set(ref _customer, value)) SaveCommand.RaiseCanExecuteChanged(); }
    }
}

// Driving it from a console: Save starts disabled, setting Customer raises
// PropertyChanged and re-evaluates CanExecute, and setting the same value
// again raises nothing.
// Output:
// Save enabled: False
// Changed: Customer
// Save enabled: True
// Saved order for Ada
Hand-written MVVM plumbing: a change-notifying base class, a command with CanExecute, and a view model that enables Save only when a name is entered.
  • Why does the UI not update when I change a property? The property does not raise PropertyChanged, raises it with the wrong name, or the binding path is wrong. Check the Output window for binding errors, or raise the trace level with PresentationTraceSources.TraceLevel=High on that binding.
  • Why compare the old and new value before raising the event? It avoids extra layout and binding work, and it prevents loops when two properties update each other.
  • What is a dependency property and why does WPF need one? A property stored by the WPF property system rather than a backing field. It supports binding targets, styles, animation, inheritance, default values and change callbacks. Only dependency properties can be the target of a binding.
  • What is an attached property? A dependency property defined by one class but set on another, such as Grid.Row on a Button. Attached behaviors use the same trick to add features to existing controls.
  • What decides a dependency property's effective value? A precedence order. Roughly: coercion and active animations win, then a local value, then values from templates and style triggers, then style setters, then the default style, inherited values and finally the default. Saying that a local value beats a style setter, which surprises many people, is the key point.
  • ObservableCollection or List for a bound list? ObservableCollection raises CollectionChanged when items are added or removed. A List does not, so the screen will not notice new items. Item property changes still need INotifyPropertyChanged on each item.
  • How do you sort or filter a bound list without changing the source? Use an ICollectionView from CollectionViewSource.GetDefaultView, set SortDescriptions or a Filter predicate, and call Refresh when the filter input changes.
  • What is an IValueConverter for, and when is it a smell? It changes a value for display, such as bool to Visibility. When converters carry business rules, the logic belongs in the view model, where it can be tested.
  • IDataErrorInfo, INotifyDataErrorInfo or ValidationRule? ValidationRule runs in the binding. IDataErrorInfo is the older synchronous interface. INotifyDataErrorInfo supports several errors per property and asynchronous checks, which suits server-side validation.
  • How do commands reach a button inside a DataTemplate? Bind to a command on the item, or reach the parent view model with a RelativeSource AncestorType binding to the list's DataContext.
using System;
using System.Windows;

public class Gauge : DependencyObject
{
    public static readonly DependencyProperty ValueProperty =
        DependencyProperty.Register(
            "Value", typeof(double), typeof(Gauge),
            new PropertyMetadata(0.0, OnValueChanged, CoerceValue));

    public double Value
    {
        get { return (double)GetValue(ValueProperty); }
        set { SetValue(ValueProperty, value); }
    }

    private static object CoerceValue(DependencyObject d, object raw)
    {
        double v = (double)raw;
        return Math.Max(0.0, Math.Min(100.0, v));
    }

    private static void OnValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        Console.WriteLine("Value " + e.OldValue + " -> " + e.NewValue);
    }
}

// g.Value = 40;   prints Value 0 -> 40
// g.Value = 250;  prints Value 40 -> 100 (coerced)
// g.Value = 100;  prints nothing, the value did not change
// g.ClearValue(Gauge.ValueProperty);  prints Value 100 -> 0
A dependency property with a change callback and coercion. Setting 250 is clamped to 100, and ClearValue drops back to the default.

A frequent follow-up: why must the CLR wrapper (the Value getter and setter) contain nothing but GetValue and SetValue? Because XAML and bindings set the value through the property system directly and skip the wrapper, so any extra logic placed there silently never runs. Put it in the callback or coercion instead.

Templates, styles and XAML reading

<ListBox ItemsSource="{Binding Orders}"
         SelectedItem="{Binding SelectedOrder}"
         VirtualizingPanel.VirtualizationMode="Recycling">
  <ListBox.ItemTemplate>
    <DataTemplate>
      <StackPanel Orientation="Horizontal">
        <TextBlock Text="{Binding Customer}" />
        <TextBlock Text="{Binding Total, StringFormat=C}" Margin="8,0,0,0" />
        <Button Content="Delete"
                Command="{Binding DataContext.DeleteCommand,
                          RelativeSource={RelativeSource AncestorType=ListBox}}"
                CommandParameter="{Binding}" />
      </StackPanel>
    </DataTemplate>
  </ListBox.ItemTemplate>
</ListBox>
Reading exercise (not executed): what does each binding resolve against, and why does the button stay enabled?
Questions an interviewer may ask about that snippet and about styling in general
QuestionWhat it testsWhat a strong answer shows
What is the DataContext inside the DataTemplate?Binding scopeEach Order item, so Customer and Total bind to the order. The Delete command lives on the window's view model, hence the ancestor binding.
Why might Delete stay enabled after the list empties?Command stateCanExecute is only re-queried when CanExecuteChanged fires. The view model must raise it when Orders changes, or the command must hook CommandManager.RequerySuggested.
What does StringFormat=C depend on?CultureThe binding's culture, which comes from the element's Language, not the thread culture by default. Teams often set it once at startup.
How do you restyle every Button in the app?Implicit stylesA Style with a TargetType and no key in App.xaml resources. Derived controls need BasedOn or their own style.
Trigger, DataTrigger or VisualStateManager?Visual statesTriggers react to properties on the element, DataTriggers to bound data, VisualStateManager to named states with transitions, which custom control templates often use.
How do you write a custom control versus a UserControl?Control authoringA UserControl composes existing controls for one app. A custom control derives from Control, has a default template in Themes/Generic.xaml and can be fully restyled by consumers.
How do you share resources across a large app?Resource organizationMerged ResourceDictionaries split by purpose (colors, brushes, control styles), loaded once in App.xaml, with care for load order and lookup cost.
Questions an interviewer may ask about that snippet and about styling in general. Scroll sideways on a small screen.

Senior and scenario questions

  • The screen freezes for several seconds while a report loads. What do you do? Move the I/O and heavy work off the UI thread with async/await, show a busy state, and assign the results to bound properties back on the UI thread. Then measure: if the freeze remains, the cost is in layout or rendering of too many elements, not in the load.
  • Why do you get "The calling thread cannot access this object because a different thread owns it"? WPF objects have thread affinity to the Dispatcher that created them. Marshal updates with Dispatcher.InvokeAsync, or let await resume on the UI context. For a collection filled from a worker, BindingOperations.EnableCollectionSynchronization is an option.
  • A grid with tens of thousands of rows scrolls badly. Where do you look? Confirm UI virtualization is active: a virtualizing panel, item scrolling, no ScrollViewer wrapping the list, and grouping configured to keep virtualization. Then use recycling mode, lighter item templates and fixed row heights where possible.
  • Memory keeps growing as users open and close windows. Common causes? Event handlers from long-lived objects (a static service or a timer) holding closed views alive, bindings to plain CLR properties on objects without change notification, and DispatcherTimers never stopped. Weak event patterns and explicit cleanup fix most of them; a memory profiler comparison of two snapshots proves it.
  • What is a Freezable and why freeze brushes? Brushes, geometries and similar objects derive from Freezable. A frozen one cannot change, so WPF stops tracking changes to it, and it can be shared across threads.
  • Where does code-behind belong in MVVM? Pure view concerns, such as focus, scrolling into view or a drag adorner, can live in code-behind or a behavior. Rules, state and calls to services belong in the view model.
  • How do view models open dialogs or navigate without referencing views? Inject a dialog or navigation service behind an interface, so tests can replace it.
  • How do you test a view model? As a plain class in unit tests: set properties, run commands, assert state and calls to fake services. Async commands need awaitable entry points so tests can wait for them.
  • MVVM toolkit or hand-written? Toolkits such as CommunityToolkit.Mvvm or Prism remove boilerplate (source-generated properties and commands, regions and modules). Knowing the hand-written version tells you what the generated code does when something breaks.
  • How do WPF and WinForms coexist in one app? WindowsFormsHost hosts WinForms controls inside WPF, ElementHost does the reverse. Airspace rules mean the two cannot overlap or blend visually.
  • How would you move a .NET Framework WPF app to current .NET? Inventory dependencies first, convert projects to the SDK style, replace or isolate libraries that do not support current .NET, then run the app and fix behavioral differences module by module. WPF on current .NET still runs only on Windows.
  • WPF, WinUI or a cross-platform UI for a new app? Answer from requirements: Windows-only with a large existing XAML codebase favors staying on WPF; Mac or mobile reach points to a cross-platform stack. Name the trade-offs instead of a favorite.

A worked senior answer

Fictional example

Senior candidate: a blotter screen that froze on open
Interviewer
Tell me about a WPF performance problem you fixed.
Candidate
We had a trade blotter that froze for around six seconds when opened. My first guess was the database, but a profiler showed the query took under a second. Most of the time went into creating and laying out rows.
Candidate
Someone had wrapped the DataGrid in a ScrollViewer for styling, which turned off virtualization, so every row was built up front. I removed the wrapper, switched to recycling mode, fixed the row height and replaced a converter-heavy cell template with precomputed display strings in the row view model.
Candidate
Open time dropped to about a second, and scrolling stopped stuttering. I added a short note to our XAML review checklist so the ScrollViewer mistake would not return.

A one-week WPF practice plan

  1. Write the MVVM plumbing above from memory, then the same view model with a toolkit, and compare what was generated.
  2. Build a master-detail screen: a list, a details form with INotifyDataErrorInfo validation, and Save and Delete commands with correct CanExecute.
  3. Break it on purpose: a wrong binding path, a missing PropertyChanged, an update from a background thread. Read the error each time.
  4. Load ten thousand fake rows, turn virtualization off and on, and note the difference you can see and measure.
  5. Restyle a Button with a ControlTemplate and a VisualStateManager hover state, then explain the visual tree you created.
  6. Say your freeze, memory leak and migration answers out loud in under two minutes each.

For the out-loud part, Natively, an AI interview assistant for Mac and Windows, can transcribe a mock round so you can reread how you explained value precedence or the Dispatcher and spot where you rambled. During practice it can read a XAML snippet or a binding error from a screenshot and suggest what to check, and it gives coding help on a C# exercise. With Pro or the free trial, adding your résumé and the job description lets its suggested answers lean on your real desktop projects, and the transcript and notes stay available to review later.

Questions people ask

What WPF questions are asked in interviews?

Expect XAML and the visual tree, binding modes and DataContext, dependency and attached properties, INotifyPropertyChanged and ICommand, styles versus templates, and the Dispatcher. Senior rounds add virtualization, memory leaks and testing view models.

What is MVVM in WPF?

Model-View-ViewModel: the view is XAML bound to a view model that exposes state and commands and raises change notifications. The view model holds no reference to the view, so it can be unit tested.

Why does my WPF binding not update the UI?

Usually the source property does not raise PropertyChanged, raises it with the wrong name, or the binding path or DataContext is wrong. The Output window lists binding errors.

Is WPF still worth learning for interviews?

Yes, if you target Windows line-of-business work. Many banking, healthcare, manufacturing and internal tools still run on WPF, and it runs on current .NET on Windows.

Where to go next

Practice with the same assistant you would use on a call: it listens, transcribes and suggests answers from your own resume and the job description.

Facts on this page were last checked on . Product details come from the Natively app itself; if something here is out of date, tell us at hello@heynatively.com.

Keep reading

Put it on your own machine.

A live-conversation assistant that runs locally. Your conversations stay on your machine.

macOS 12+ · Windows 10/11

© 2026 Natively AI Private Limited

Source-available under the Natively Personal Use Source License v1.0 · IP geolocation by DB-IP