WPF Interview Questions for Beginners & Advanced – Part 5

81. What is Property-based Animation in WPF?

WPF introduces a property-based animation techniques to make animations in WPF easy.

It simply modify the value of control property over an interval of time and the target property must be a dependency property.

82. How many types of Animation support by WPF?

There are basically three types of Animation classes.

  1. Linear interpolation Animation
  2. Keyframe Animation
  3. Path based Animation

83. What is Linear Interpolation Animation?

This animation technique increment a control property e.g. width or height one by one point between start and finish value and during a fixed time.

<DoubleAnimation Storyboard.TargetName="myButton" Storyboard.TargetProperty="Height" From="160" To="300" Duration="0:0:5" />

84. What is KeyFrame Animation?

This animation technique animate the property value of a control. But Keyframe animation have multiple target values defined by the KeyFrame objects.

<DoubleAnimationUsingKeyFrames
	Storyboard.TargetName="myButton"
	Storyboard.TargetProperty="Width"
	Duration="0:0:10">
	<LinearDoubleKeyFrame Value="0" KeyTime="0:0:0" />
	<LinearDoubleKeyFrame Value="350" KeyTime="0:0:2" />
	<LinearDoubleKeyFrame Value="50" KeyTime="0:0:7" />
	<LinearDoubleKeyFrame Value="200" KeyTime="0:0:8" />                          
</DoubleAnimationUsingKeyFrames>

85. Can you tell me some KeyFrame animation types?

Yes, There are around 20 KeyFrame animations types. Some of these are:

  • BooleanAnimationUsingKeyFrames
  • ByteAnimationUsingKeyFrames
  • ColorAnimationUsingKeyFrames
  • DecimalAnimationUsingKeyFrames
  • DoubleAnimationUsingKeyFrames
  • PointAnimationUsingKeyFrames
  • ThicknessAnimationUsingKeyFrames

89. What is Path based animation?

This animation technique animate a property value of control correspond with the shape describe by PathGeometry object.

<MatrixAnimationUsingPath
  Storyboard.TargetName="myButton"
  Storyboard.TargetProperty="Height"
  DoesRotateWithTangent="True"
  Duration="0:0:5" 
  RepeatBehavior="Forever" >
	<MatrixAnimationUsingPath.PathGeometry>
	  <PathGeometry 
		Figures="M 10,100 C 35,0 135,0 160,100 180,190 285,200 310,100" 
		PresentationOptions:Freeze="True" />
	</MatrixAnimationUsingPath.PathGeometry>
  </MatrixAnimationUsingPath>

90. What is the standard frame rate for Animation in WPF?

The standard frame rate is 60 frames per second.

91. Can you tell me some common properties of Animation classes.

  • From: Starting value from which the animation starts
  • To: End value on which the animation ends
  • Duration: Time limit for the animation
  • By: Change the value of From property by adding the By value.
  • FillBehavior: There are two values of this property.
  • HoldEnd: If keep the animated value in the property of control after the animation ends
  • Stop: If revert the animated value and set the original value before the animation to property of control.

92. What is Storyboard?

Storyboard is the container for animations classes. It is used for apply grouping on animations and also used for controling the animation like pause, stop etc.

<Storyboard x:Name="myStoryboard">
	<DoubleAnimation 
		Storyboard.TargetName="myButton" 
		Storyboard.TargetProperty="Height" 
		From="160" To="300" Duration="0:0:5" />
</Storyboard>

93. What is TargetName and TargetProperty of Storyboard?

TargetName is used for setting the target control name and Target Property is used for setting the target property of control.

94. What is EventTrigger?

EventTrigger is used for starting an animation when an event occurred on control.

<Button>
	<Button.Triggers>
		<EventTrigger RoutedEvent="Button.Click">
			<EventTrigger.Actions>
				<BeginStoryboard>
					<Storyboard>
						<DoubleAnimation Storyboard.TargetProperty="Width" To="300" Duration="0:0:3" />
					</Storyboard>
				</BeginStoryboard>
			</EventTrigger.Actions>
		</EventTrigger>
	</Button.Triggers>
</Button>

95. How can you control the Storyboard?

There are several classes available in WPF for controlling Storyboard.

  • PauseStoryboard: Stops storyboard animation
  • ResumeStoryboard: Resume storyboard animation
  • StopStoryboard: Stop storyboardanimation
  • SeekStoryboard: Jumps to specific position in storyboard

96. What are Easing functions in WPF?

Easing functions are used for make more natural look for animations.

<Storyboard x:Name="myStoryboard">
	<DoubleAnimation Storyboard.TargetName="btnGrow" Storyboard.TargetProperty ="Width" To="300" Duration="0:0:2">
		<DoubleAnimation.EasingFunction>
			<ElasticEase EasingMode="EaseIn" Oscillations="5" />
		</DoubleAnimation.EasingFunction>
	</DoubleAnimation>
</Storyboard>

97. Can you give some examples of Easing functions.

There are multiple easing functions in WPF.

  1. BackEase
  2. ElasticEase
  3. BounceEase
  4. CircleEase
  5. CubicEase

98. What is Easing In and Easing Out?

These are used in Easing functions.

EaseIn means easing function effect is applied to the starting of animation.

EaseOut means easing function effect is applied to the end of animation.

EaseInOut means easing function effect is applied at both starting and end of animation.

99. Can we use Win32 controls in WPF?

Yes, WPF provides two assemblies for working with Win32 controls.

  • System.Windows.Interop
  • System.Windows.Forms.Integration

100. How you can add Window form control in WPF?

You need to use WindowsFormHost object and assign the Windows Form control as its child control.

<Grid>
	<WindowsFormsHost>
		<wf:Button x:Name="winFormButton" Text="Hello Windows Forms" Width="150" />
	</WindowsFormsHost>
</Grid>