WPF Interview Questions And Answers

WPF Interview Questions and Answers

Question 33: What are various ways of doing alignment in WPF?

Answer:The FrameworkElement has two alignment properties: HorizontalAlignment and Vertical Alignment. The Horizontal Alignment property is a type of HorizontalAlignment enumeration and represents how a child element is positioned within a parent element horizontally.

The HorizontalAlignment enumeration has the four properties Left, Center, Right and Stretch. The Left, Center and Right properties sets a child element to left, center and right of the parent element. The Stretch property stretches a child element to fill the parent elements allocated layout space.

Example

The VerticalAlignment property is a type of HorizontalAlignment enumeration and represents how a child element is positioned within a parent element vertically.

The VerticalAlignment enumeration has the four properties Top, Center, Bottom and Stretch. The Top, Center and Bottom properties set a child element to top, center or bottom of the parent element. The Stretch property stretches a child element to fill the parent elements allocated layout space vertically.

Example

See for more details:

Question 9: What is the Data Binding concept and How Binding works in WPF?

Answer: Data Binding is one of the greatest and most powerful features of XAML (WPF, Silverlight, Windows Phone or Windows 8) compared to other traditional web and Windows app technology in .NET. There was simple data binding for displaying single values, and complex data binding for displaying and formatting a bunch of data. XAML (WPF, Silverlight, Windows Phone or Windows 8 ) however makes it easy to bind nearly any property to any element or object or data source. You take data from some property or object or dependency property and bind it to another dependency property or object or else directly to an element. In a single word you can say in XAML “Data binding is the process of getting information from one object to another and displaying it in one or more elements in the user interface”.

How {Binding} works in WPF

The Binding keyword looks as in the following . Here is the binding of TextBox UI controls with some binding property source object.

Binding to a WPF element from code behind.

In the above sample a TextBox and slider from code behind using some binding property.

Some Very Useful Properties of the Binding Class

Property Name Description
Element Name The name of the element that gets or sets the binding source object when binding to a XAML element.
FallbackValue Set the value to use when the binding does not return values.
Converter Set the converter for the UI element.
Mode Set the Binding diection between the target and source objects.
Path Get or Set the path to the source property of the Binding source.
RelativeSource Gets or Sets the binding source by specifying its location and relative to the postion of the binding target.
Source Gets or Sets the binding source when not binding to a WPF element.
StringFormat
UpdateSourceTrigger
ValidationRules
NotifyOnSourceUpdated Gets or sets the value determining the direction of the dataflow in the binding.
NotifyOnTargetUpdated Gets or sets a value that indicates whether to raise the source Update event when a value is transferred from the source to the target.

See for more details:

Question 11: What is Prism in WPF?

Answer: Prism (Composite Application Guidance for WPF and Silverlight) is designed to build applications in WPF and Silverlight that have a single code base. It helps to develop the client application in a modular fashion so that complexity of a large application can be divided into simpler modules.

In other words “Prism is developed by Microsoft Patterns and Practices and provides guidance designed to help you to more easily design and build rich, flexible and easy-to-maintain Windows Presentation Foundation (WPF) desktop applications.”.

Architecture: The following diagram shows basic architecture:

  • App.XAML: Call Boot Strapper on Application_Startup.
  • BootStrapper: This is a class file that calls Shell (Shell.XAML) and so creates catalogue of module.
  • Shell: This is like a Master Page having regions.
  • Region: It is like placeholders to register views.
  • View: This is XAML file having User Interface
  • Module: Each module can have one or more View(s) which are registered to Region (in the Shell) through Region Manager.
  • See for more details:

    Related Posts

    Leave a Reply

    Your email address will not be published. Required fields are marked *