41. What is Markup Extension in WPF?
Markup Extension decides at runtime how to set a property value. StaticResource, DynamicResource are examples of Markup Extension.
Markup Extension are always comes in curly braces { }. The first word inside the curly braces is class name of Markup Extension.
42. How many types of Markup Extension exists in WPF?
There are totally 9 types of Markup Extension.
- Null Extension
- Type Extension
- Array Extension
- Static Extension
- StaticResource Extension
- DynamicResource Extension
- ComponentResourceKey Extension
- Binding Extension
- RelativeSource Extension
- TemplateBinding Extension
43. What is Null Markup Extension?
Null Extension is used for set the property value to NULL.Â
<Button Background="{x:Null}" Content="Click Me" />
44. What is Type Markup Extension?
Type markup extension returns a “type” object. It’s just like the GetType() method.
It is mainly used in styles in the TargetType property.
<Style TargetType="{x:Type Button}">
...
</Style>
45. What is Array Extension?
Array markup extension allows you to create an array of objects in the XAML.
<x:ArrayExtension x:Key="brushes">
<SolidColorBrush Color="Red" />
<SolidColorBrush Color="Blue" />
<SolidColorBrush Color="Green" />
<x:ArrayExtension>
<ListBox ItemsSource="{StaticResource brushes}">
</ListBox>
46. What is Static Extension in WPF?
Static extension is used for set the target property to the value of specified static property or field.
<Button Background="{x:Static SystemColors.HighlightBrushKey}" Text="Hello" />
47. What is StaticResource Extension?
StaticResource extension associate the value of specific resource to control property. After resource value is set to target property of control, it will not updated when you update the resource value.
<Button Background="{StaticResource BlueBrush}" />
48. What is DynamicResource Extension?
DynamicResource extension also associate the value of specific resource to control property but it’s value will be updated when you change the resource after binding.
<Button Background="{DynamicResource BlueBrush}" />
Same resource can be used as Static and Dymamic both.
49. What is Binding Extension?
This extension is used for associate a property of class to a property of control. Whenever property of class updated it automatically reflects its value in the control property. Whenever the value of control property changed, it automatically reflects into the source class property.
50. What are Binding Modes?
There are five Binding Modes.
- Default
- OneTime
- OneWay
- OneWayToSource
- TwoWay
?51. What is Default mode in binding mode?
Default mode is depends on the control. If user can change the state of control, then the binding behaves as TwoWay else OneWay.
52. What is OneTime binding mode?
It updates the target property of control only once. After that if you have changed the source property, it will not reflects into the target property of control.
53. What is OneWay binding mode?
This binding only update the target property of control, if you update the source property of binded class, then the value will not reflect the target property of control.
54. What is OneWayToSource binding mode?
This binding is opposite to OneWay binding and this will update the source property when there is a change in the target property of control.
55. What is TwoWay binding mode?
This is the combination of OneWay and OneWayToSource propety. It update the target property of control, whenever there is a change in the source property and it will also update the source property whenever there is a change in target property of control.
56. Is user interface in WPF is single threaded?
Yes, the owner of UI is the thread that created the window.
57. What are the advantages of using threading in WPF?
There are two advantages:
- It does not freeze the UI during processing.
- You can use multiple cores of system.
58. How can you update the UI from different thread than UI thread?
You can use the Dispatcher class.
Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() =>
{
lblHeader.Text = "Hello World";
}));
59. What are the main methods available in Dispatcher class?
There are two methods available:
- Invoke – Synchronous
- BeginInvoke – Asynchronous
60. Is there any other class available for updating the UI from non-UI thread?
Yes, you can use SynchronizationContext class.