| WPF-Routed-Events | WPF-Question-Answers-51-60 | |
WPF (Windows Presentation Foundation) Question Answers - (41–50) |
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"/>
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";
}));
}
CoerceValueCallback is a delegate that defines a method called whenever a dependency property value is re-evaluated or coercion is requested.
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.
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.
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.
ContentPresenter is a placeholder for XAML content, often used inside control templates to display runtime content.
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.
Data binding establishes a connection between the UI and business logic. It allows automatic synchronization of UI elements with data sources.
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).
| WPF-Routed-Events | WPF-Question-Answers-51-60 | |