Saturday 18 February 2017

WPF interview question Part 1

1. Ques: Explain the architecture of WPF ?
Answer:


WPF architecture 3 layered architecture which have Managed layered, Unmanaged layered, Core API layered 

Managed layered : This layer has tow part Presentation Framework and Presentation Core.
  • Presentation Framework: This section has features like application controls , layouts . Content etc which helps you to build up your application. PresentationFamework DLL is responsible for this layer. 
  • Presentation Core: This is a low level API exposed by WPF providing features for 2D , 3D , geometry etc.
Unmanaged layered: this layer also called as MiliCore API Layer. Mili stands for media integration library. This section is a unmanaged code because it acts like a bridge between WPF managed and DirectX / User32 unmanaged API.

Core API layered : This layer has OS core components like Kernel, User32, GDI, Device Drivers, Graphic cards etc. These components are used by the application to access low level APIs. User32 manages memory and process separation.


2. Ques:What is dependency property? What are the Advantages of a Dependency Property and why we use it?
Answer:
  • Dependency property is a specific type of property which extends the CLR property. 
  • It is a property whose value depends on the external sources, such as animation, data binding, styles, or visual tree inheritance.
  • Dependency property also has the builtin feature of providing notification when the property has changed, data binding and styling.
Advantages of a Dependency Property:-
  • Less memory Uses:The Dependency Property stores the property only when it is altered or modified. Hence a huge amount of memory for fields are free.
  • Property value inheritance:It means that if no value is set for the property then it will return to the inheritance tree up to where it gets the value.
  • Change notification and Data Bindings:Whenever a property changes its value it provides notification in the Dependency Property using INotifyPropertyChange and also helps in data binding.
  • Participation in animation, styles and templates:A Dependency Property can animate, set styles using style setters and even provide templates for the control.
  • CallBacks: Whenever a property is changed you can have a callback invoked.
  • Resources:You can define a Resource for the definition of a Dependency Property in XAML.
Dependency Property can used for -
  • If you want to set the style
  • If you want data binding
  • If you want to set with a resource (a static or a dynamic resource)
  • If you want to support animation

3. Ques: What is routed event ?
Answer:
A routed event is event that can invoke handlers on multiple listeners in an element tree rather than just the object that raised the event. RoutedEvents has three type
  • Direct Event
  • Bubbling Event
  • Tunnel Event
Direct event is similar to events in Windows forums which are raised by the element in which the event is originated.

Bubbling Event
A bubbling event begins with the element where the event is originated. Then it travels up the visual tree to the topmost element in the visual tree. So, in WPF, the topmost element is most likely a window.

Tunnel Event
Event handlers on the element tree root are invoked and then the event travels down the visual tree to all the children nodes until it reaches the element in which the event originated.


4. Ques: Explain the WPF object hierarchy?
Answer:-

Object
: - Object is the main class for all .Net classes and  it is the base class for all wpf classes.

Dispatcher: -It is the base class for any object which wants to accessed only by its own thread. It means the object that derives from DispatcherObject is going to be accessed by only its own thread and if any other thread tries to access that object gives error. In this way DispatcherObject object provides Thread-Safe environment. Most of the WPF classes derive from the DispatcherObject object to provides the Thread-Safe environment.

DependencyObject: If any object supports dependency properties in WPF means it derives from the base class DependencyObject. DependencyObject provides GetValue() & SetValue() methods that are central to dependency properties.

Visual: - Visual is the base class for all objects which has their own visual representation.

UI Element: - It is the base class for all Visual objects with supported events, command binding, layout, focus...etc.

Framework element: - This class supports for templating , styles , binding , resources and common mechanisms for Windows-based controls such as tooltips and context menus.

5. Ques: Explain the Framework element hierarchy?
Answer:-





























6. Ques: what is prism in WPF ?
Answer:
Prism is the Microsoft Patterns and Practices Team official guidance for building "composite applications" in WPF and Silverlight. Its intended to provide guidance on the best practices for building large scale applications which are flexible in terms of development and maintainability.


7. Ques: What is the Application Lifetime in WPF?
Answer:
 The main events fired from Application include:

Startup :
Application is starting up.

Exit :
Fired when an application is shutting down.

Activated :
Fired when an application gets focus, i.e. becomes the foreground application

Deactivated :
Fired when application loses focus, i.e. is no longer the foreground application

DispatcherUnhandledException :
Fired when an exception is thrown, but not yet handled. You canchoose to handle the exception or not

SessionEnding :
Fired when Windows is being shut down due to either logoff or Windows shutdown.You can cancel the shutdown sequence.

You can add custom code for any of these events by just overriding the OnEventName method in yourApplication-derived class, e.g. OnStartup

No comments:

Post a Comment

Thank you for comment