| WPF QA 121-130 :👈 | 👉:WPF-QA-1-10 |
WPF (Windows Presentation Foundation) Question Answers - 131 to 140 |
WPF Interview Questions and Answers
131. What is Dependency Property in WPF?
A Dependency Property is a property managed by the WPF property system rather than by a .NET class field.
Advantages:
- Data Binding support.
- Animation support.
- Styling support.
- Default values.
- Property value inheritance.
- Change notification.
Example:
public static readonly DependencyProperty TitleProperty =
DependencyProperty.Register(
"Title",
typeof(string),
typeof(MyControl));
132. What are Commands? How Do They Work in WPF?
Commands provide a way to separate UI actions from business logic.
Command Components:
- Command
- Command Source (Button/MenuItem)
- Command Target
- Command Binding
Example:
<Button Command="ApplicationCommands.Copy"
Content="Copy"/>
When the button is clicked, WPF routes the command to the appropriate command handler.
133. What is a Routed Event in WPF?
A Routed Event is an event that can travel through the visual tree of controls.
Types:
Bubbling Event
Event moves from child to parent.
Tunneling Event
Event moves from parent to child. Tunneling events start with Preview.
Direct Event
Raised and handled by the same control.
Example:
Button Click Event - Bubbling
PreviewMouseDown - Tunneling
134. What is Window Manager?
Window Manager is the operating system component responsible for managing application windows.
Responsibilities:
- Window creation and destruction.
- Window positioning.
- Focus handling.
- Z-order management.
- Window resizing.
- Rendering coordination.
In WPF, windows interact with the Windows Desktop Window Manager (DWM).
135. What is Class Hierarchy in WPF?
WPF controls are organized in an inheritance hierarchy.
Object
|
DispatcherObject
|
DependencyObject
|
Visual
|
UIElement
|
FrameworkElement
|
Control
|
Button
Each level adds additional functionality such as rendering, events, layout support, styling, and templating.
136. Different Types of Layouts in WPF
Grid
Arranges controls in rows and columns.
StackPanel
Arranges controls vertically or horizontally.
WrapPanel
Places controls in sequence and wraps to the next line when needed.
DockPanel
Docks controls to Top, Bottom, Left, or Right.
Canvas
Provides absolute positioning using coordinates.
UniformGrid
Places controls in equal-sized cells.
137. What is Adorner Layer?
An Adorner Layer is a special rendering layer in WPF used to display visual elements on top of existing controls without affecting their layout.
Common Uses:
- Validation error indicators.
- Selection handles.
- Drag-and-drop visuals.
- Resize handles.
- Design-time decorators.
Adorners are rendered in an AdornerLayer and always appear above regular UI elements.
Example:
AdornerLayer layer =
AdornerLayer.GetAdornerLayer(myControl);
layer.Add(new MyAdorner(myControl));
Final Interview Revision
| Concept | Key Point |
|---|---|
| Style | Reusable property settings. |
| ControlTemplate | Defines a control's visual structure. |
| DataTemplate | Defines how data is displayed. |
| Binding | Connects UI properties to data. |
| FrameworkElement | Adds framework-level UI services. |
| INotifyPropertyChanged | Notifies observers of property changes. |
| ResourceDictionary | Stores reusable WPF resources. |
| UserControl | Combines existing controls. |
| Custom Control | Supports reusable, template-based control design. |
| Converter | Transforms binding values. |
| Routed Event | Travels along an event route. |
| Command | Represents an executable UI action. |
| Grid | Organizes elements into rows and columns. |
| HierarchicalDataTemplate | Displays parent-child collections. |
| ItemsPresenter | Presents an items panel in a control template. |
| ContentPresenter | Displays content in a control template. |
| Trigger | Applies behavior based on conditions or events. |
| Dispatcher | Schedules work on the owning UI thread. |
| Task.Run / BackgroundWorker | Runs suitable work away from the UI thread. |
Official Documentation
| WPF QA 121-130 :👈 | 👉:WPF-QA-1-10 |