*
Previous C# Threading QA-41-50 WPF-Question-Answers-11-20 Next

WPF (Windows Presentation Foundation) Question Answers - (1–10)

WPF Interview Questions (1–10)

1. Define routed events in WPF

Routed events are more comprehensive than standard CLR events. Instead of only invoking handlers on the element that raised the event, WPF walks the UI tree and invokes handlers attached to any node from the originating element up to the root. This event routing behavior is the defining feature of routed events and is central to event handling in WPF.

2. Types of documents supported by WPF

  • Flow format: Adjusts to screen size and resolution.
  • Fixed format: Does not adjust to screen size and resolution.

3. Difference between object pooling and connection pooling

Connection pooling

  • Purpose: Pools database connections.
  • Benefit: Reduces the number of times new connections must be opened.
  • Ownership: Pooler maintains ownership of the physical connection.
  • Open: Returns an available pooled connection if one exists; otherwise opens a new one.
  • Close: Returns the connection to the pool instead of closing it.
  • Compatibility: Only connections with the same configuration are pooled.
  • Impact: Improves performance and scalability.

Object pooling

  • Purpose: Pools any kind of object.
  • Benefit: Useful when objects are expensive to create or destroy.
  • Acquire: Returns an existing object from the pool if available; otherwise creates a new one.

4. Dispatcher shutdown behavior

If a Dispatcher is shut down, it cannot be restarted.

5. Explain FrameworkContentElement in WPF

FrameworkContentElement is the framework-level implementation that extends ContentElement. It adds support for additional input APIs (tooltips, context menus), storyboards, data context for data binding, styles, and logical tree helper APIs.

6. Explain attached events in WPF

Attached events follow four actions: define, add handler, remove handler, and raise.

  • Define:
    public static RoutedEvent MyEvent =
        EventManager.RegisterRoutedEvent(...);
  • Add handler:
    myObject.AddHandler(MyEvent, eventHandlerFunction, ...);
  • Remove handler:
    myObject.RemoveHandler(MyEvent, eventHandlerFunction);
  • Raise:
    myObject.RaiseEvent(routedEventArgs);

myObject should be a FrameworkElement to detect and handle routed events. routedEventArgs should reference the static RoutedEvent defined as MyEvent.

7. Explain ControlTemplate and DataTemplate

  • ControlTemplate: Describes how a control is displayed, independent of underlying data. Typically uses TemplateBinding to bind to the control’s own properties.
  • DataTemplate: Describes how data is displayed. Binds to properties of the DataContext (domain object or view model) using standard bindings.

8. Explain FrameworkElement in WPF

FrameworkElement provides framework-level properties, events, and methods for WPF elements. It builds on core APIs defined by UIElement and enables styling, data binding, layout, and more.

9. Explain MultiBinding and IMultiValueConverter

MultiBinding binds a target property to multiple source properties and uses an IMultiValueConverter to produce a single value for the target.

Example: Two TextBoxes for first and last name can feed a “Full Name” TextBlock via MultiBinding; the converter composes the full name.

10. Explain OneWay, TwoWay, OneTime, and OneWayToSource

  • OneWay: Source updates flow to target; target changes do not update source. Good for read-only UI values.
  • TwoWay: Changes to source or target update the other. Ideal for editable forms and interactive UI.
  • OneWayToSource: Target updates flow to source (reverse of OneWay). Useful for UI-to-model scenarios like a password input.
  • OneTime: Source initializes target once; subsequent changes don’t propagate.
Back to Index
Previous C# Threading QA-41-50 WPF-Question-Answers-11-20 Next
*
*