WPF Interview Questions for Beginners & Advanced - Part 3

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.

  1. Null Extension
  2. Type Extension
  3. Array Extension
  4. Static Extension
  5. StaticResource Extension
  6. DynamicResource Extension
  7. ComponentResourceKey Extension
  8. Binding Extension
  9. RelativeSource Extension
  10. 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.

  1. Default
  2. OneTime
  3. OneWay
  4. OneWayToSource
  5. 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:

  1. It does not freeze the UI during processing.
  2. 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:

  1. Invoke - Synchronous
  2. BeginInvoke - Asynchronous

60. Is there any other class available for updating the UI from non-UI thread?

Yes, you can use SynchronizationContext class.

WPF Interview Questions

Join our newsletter and get an occasional email with a technology and dotnetpattern.com news update.