| Code Coverage and Static Analysis in C# | WPF-Question-Answers-71-80 | |
WPF (Windows Presentation Foundation) Question Answers - (61–70) |
Invoke method takes an Action or Delegate and executes the method synchronously. That means it does not return until the Dispatcher completes the execution of the method.
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Task.Factory.StartNew(() =>
{
InvokeMethodExample();
});
}
private void InvokeMethodExample()
{
Thread.Sleep(2000);
Dispatcher.Invoke(() =>
{
btn1.Content = "By Invoke";
});
}
}
This code creates a new thread using Task.Factory and updates the button content via Dispatcher.Invoke to avoid System.InvalidOperationException.
Visual Tree: Represents all elements in the UI that render to an output device (e.g., Border, AdornerDecorator, ContentPresenter). Event routes for routed events mostly travel along the visual tree.
Logical Tree: Represents the essential structure of the UI (e.g., Window, Grid, Button, Label). Used for resource lookup and notifications when elements are loaded.
Represents the callback invoked when the effective property value of a dependency property changes. Often used to update internal state when a public property changes.
Describes the location of the binding source relative to the binding target. Valid values:
{Binding RelativeSource={RelativeSource Self}}
{Binding RelativeSource={RelativeSource Self}, Path=Name}
{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=Title}
{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}, AncestorLevel=2}, Path=Name}
{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Name}
{TemplateBinding Name}
In MVVM Light Toolkit, RelayCommand implements ICommand. It requires an Execute delegate and optionally a CanExecute delegate returning a Boolean.
A routed event can invoke handlers on multiple listeners in an element tree, not just the object that raised the event. Backed by RoutedEvent and processed by the WPF event system.
In data binding, the source contains the data, and the target is the control displaying that data.
Markup languages like XAML or HTML provide a common medium for designers and developers, and allow a declarative approach to building applications.
A Panel arranges multiple child elements; a Decorator has only one child and applies additional behavior to it.
PropertyChangedCallback executes only when the property value changes. CoerceValueCallback executes every time a value is assigned, even if it’s the same as the old value.
| Code Coverage and Static Analysis in C# | WPF-Question-Answers-71-80 | |