WPF Interview Questions for Beginners & Advanced - Part 4

61. How can you obtain the SynchronizationContext class?

You can use the static property SynchronizationContext.Current property from the UI thread.

62. How many methods are available in SynchronizationContext class?

There are two methods:

  1. Post
  2. Send

63. What is the difference between Send and Post methods in SynchronizationContext class?

Post method is asynchronous method and Send method is synchronous.

64. How SynchronizationContext is different from Dispatcher?

You can only used Dispatcher in WPF scenarios. But Synchronization works in all Windows Forms, Silverlight, Windows Phone and WPF.

65. What is Brush class?

Brush class is used for filling the color into the border, foreground and background space of visual controls.

66. How many types of Brushes available in WPF?

There are mainly six types.

  1. SolidColorBrush
  2. LinearColorBrush
  3. RadialGradientBrush
  4. ImageBrush
  5. DrawingBrush
  6. ?VisualBrush

67. What is SolidColorBrush?

This brush is used for filling the visual object to solid color like red, green, blue etc. Entire space is filled by single color.

68. What is GradientBrush?

GradientBrush is made up of multiple colors.

You can specify offsets of colors at different points. Every color is start from base offset and goes to it maximum offset.

<Rectangle>
    <Rectangle.Fill>
		<LinearGradientBrush>
			<GradientStop Color="Red" Offset="0.3" />
			<GradientStop Color="Green" Offset="0.4" />
			<GradientStop Color="Blue" Offset="0.8" />
		</LinearGradientBrush>
	</Rectangle.Fill>
</Rectangle>

Red colors starts from offset 0.3 to 0.4, green color starts from 0.4 to 0.8 and  blue color starts from 0.8 to 1.

LinearColorBrush and RadialGradientBrush are examples of Gradient brushes.

69. What is ImageBrush in WPF?

This brush allows you to paint an object with the image.

<Button>
	<Button.Background>
		<ImageBrush ImageSource="Images/House.png" Stretch="Uniform" />
	</Button.Background>
</Button>

70. What is DrawingBrush?

A DrawingBrush paints an area with a Drawing. Below is the example:

<Rectangle Width="75" Height="75">
  <Rectangle.Fill>
    <DrawingBrush Viewport="0,0,0.25,0.25" TileMode="Tile">
      <DrawingBrush.Drawing>
        <DrawingGroup>
          <GeometryDrawing Brush="White">
            <GeometryDrawing.Geometry>
              <RectangleGeometry Rect="0,0,100,100" />
            </GeometryDrawing.Geometry>
          </GeometryDrawing>

          <GeometryDrawing>
            <GeometryDrawing.Geometry>
              <GeometryGroup>
                <RectangleGeometry Rect="0,0,50,50" />
                <RectangleGeometry Rect="50,50,50,50" />
              </GeometryGroup>
            </GeometryDrawing.Geometry>
            <GeometryDrawing.Brush>
              <LinearGradientBrush>
                <GradientStop Offset="0.0" Color="Black" />
                <GradientStop Offset="1.0" Color="Gray" />
              </LinearGradientBrush>
            </GeometryDrawing.Brush>
          </GeometryDrawing>
        </DrawingGroup>
      </DrawingBrush.Drawing>
    </DrawingBrush>
  </Rectangle.Fill>
</Rectangle>

71. What is VisualBrush?

This brush is used for paints an area with any visual object. You can use any visual object like Label, Button, MediaElement.

<Button Name="MainButton" Content="Drawing Brush" Height="100" Width="100" />
<Button Height="125" Width="125">
	<Button.Background>
		<VisualBrush Visual="{Binding ElementName=MainButton}" />
	</Button.Background>
</Button>

72. What are Bitmap Effects?

These classes allows you to add blending options to visual objects such as blurring, drop shadow, outer glow, bitmap effect.

73. How many Bitmap Effects currently available in WPF?

There are six Bitmap Effects classes available.

  1. BlurBitmapEffect
  2. BevelBitmapEffect
  3. DropShadowBitmapEffect
  4. EmbossedBitmapEffect
  5. OuterGlowBitmapEffect
  6. BitmapEffectGroup
<Rectangle>
	<Rectangle.BitmapEffect>
		<BevelBitmapEffect BevelWidth="40" />
	</Rectangle.BitmapEffect>
</Rectangle>

74. What are Transformations in WPF?

Transformations allows you add special effects to visual objects like rotation, skewing, scaling, and moving.

75. How many types of Transformations available?

There are five types available:

  1. RotateTransform
  2. ScaleTransform
  3. SkewTransform
  4. TranslateTransform
  5. MatrixTransform

76. What is RotateTransform?

This transformation is used for rotate visual object in a particular angle.

<Button>
	<Button.RenderTransform>
		<RotateTransform Angle="90" />
	</Button.RenderTransform>
</Button>

77. What is ScaleTransform?

This transformation is used for resize any visual object.

<Button>
	<Button.RenderTransform>
		<ScaleTransform ScaleX="5" ScaleY="2" />
	</Button.RenderTransform>
</Button>

78. What is SkewTransform?

This transformation is used for giving 2D effects.

<Button>
	<Button.RenderTransform>
		<SkewTransform CenterX="40" CenterY="30" AngleX="20" AngleY="20" />
	</Button.RenderTransform>
</Button>

79. What is TranslateTransform?

This transformation is used for moving a visual object along the X or Y axis.

<Button>
	<Button.RenderTransform>
		<TranslateTransform X="223" Y="150" />
	</Button.RenderTransform>
</Button>

80. What is MatrixTransform?

This transformation is used for creating custom transformation.

<Button MinWidth="100">Click
	<Button.RenderTransform>
	  <MatrixTransform x:Name="myMatrixTransform">
		<MatrixTransform.Matrix >
		  <Matrix OffsetX="10" OffsetY="100" M11="3" M12="2"/>
		</MatrixTransform.Matrix>
	  </MatrixTransform>
	</Button.RenderTransform>
</Button>

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