*
Previous WPF-Routed-Events WPF-Question-Answers-51-60 Next

WPF (Windows Presentation Foundation) Question Answers - (41–50)

WPF Interview Questions (41 - 50)

41. What is Attached Properties in WPF?

Attached Properties provide a simpler and more flexible way to extend XAML. They act as global properties that can be set on any object. Typically, they are a specialized form of dependency property without the conventional property wrapper.

Example:

<TextBox Grid.Row="4" Grid.Column="2"/>

42. What is BeginInvoke Method in WPF?

BeginInvoke executes a delegate asynchronously and immediately returns before the method is called. It returns a DispatcherOperation object, which can be used to check operation status and events (Aborted, Completed).

public MainWindow()
{
    InitializeComponent();
    Task.Factory.StartNew(() =>
    {
        BeginInvokeExample();
    });
}
 
private void BeginInvokeExample()
{
    DispatcherOperation op = Dispatcher.BeginInvoke((Action)(() => {
        btn1.Content = "By BeginInvoke";
    }));
}
  

43. What is CoerceValueCallback?

CoerceValueCallback is a delegate that defines a method called whenever a dependency property value is re-evaluated or coercion is requested.

44. What is commands? How it works in WPF?

Commands in WPF decouple user actions from execution logic. Instead of wiring up click events, commands centralize logic and allow reuse across buttons, menus, and keyboard shortcuts.

45. What is ContentControl?

ContentControl is a base class for controls that contain other elements and have a Content property (e.g., Button). It uses a ContentPresenter to display its content.

46. What is ContentElement class in WPF?

ContentElement is a base class similar to UIElement, but for document-related content that has no rendering behavior. ContentElements are hosted in a Visual-derived class for rendering and may require multiple visuals to render properly.

47. What is ContentPresenter?

ContentPresenter is a placeholder for XAML content, often used inside control templates to display runtime content.

48. What is Control Class in WPF?

Control is the base class for controls like Button, ListBox, and StatusBar. It extends FrameworkElement with properties like Foreground, Background, and FontSize, and supports full restyling.

49. What is data binding?

Data binding establishes a connection between the UI and business logic. It allows automatic synchronization of UI elements with data sources.

50. What is DataContext in WPF?

DataContext allows elements to inherit information about the data source for bindings. It can be set directly to a CLR object or a DataSourceProvider.

DataContext is bindable and supports property value inheritance, but circular bindings must be avoided (e.g., binding a DataContext to itself).

Back to Index
Previous WPF-Routed-Events WPF-Question-Answers-51-60 Next
*
*