0% found this document useful (0 votes)
2K views

WPF Interview Questions

Templates define the visual structure and behavior of controls in WPF. There are different types of templates, including control templates, data templates, and hierarchical data templates. The Application object represents a WPF application and is responsible for managing the application lifetime through events like startup, exit, activation, and deactivation. These events fire in a specific order during application initialization and shutdown. Windows in WPF also fire a series of events during initialization and closing, like Initialized, Loaded, Closing, and Closed. The logical and visual trees in WPF represent the hierarchical relationship between elements, with the logical tree containing only real controls and the visual tree including all template parts.

Uploaded by

Swaroop Waghade
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views

WPF Interview Questions

Templates define the visual structure and behavior of controls in WPF. There are different types of templates, including control templates, data templates, and hierarchical data templates. The Application object represents a WPF application and is responsible for managing the application lifetime through events like startup, exit, activation, and deactivation. These events fire in a specific order during application initialization and shutdown. Windows in WPF also fire a series of events during initialization and closing, like Initialized, Loaded, Closing, and Closed. The logical and visual trees in WPF represent the hierarchical relationship between elements, with the logical tree containing only real controls and the visual tree including all template parts.

Uploaded by

Swaroop Waghade
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

WPF Interview Questions & Answers

By Jignesh Patel ([email protected]) Page 13


Question: 67What are Templates and its type in WPF?Ans:
* A Template is used to change how a control looks.* Types of templates:1) Control
template: How a control is rendered and behaves by specifying the visual structure
andbehavioral aspects.2) Data template: To specify the visualization of data objects.3)
Hierarchical data template: Used over hierarchical structure like TreeView and Menu.
Question: 68What is application object and its reponsiblity?Ans:
* Application is a class that represents a WPF application running as a standalone client
application inWindows.* Each running application contains at most a single instance of
Application.* The Application object is defined in the App.xaml file and is responsible for:Managing application lifetime (e.g. responding to startup/shutdown events)- Window,
property and resource management- Command-line processing- Navigation
Question: 69What is the Application Lifetime in WPF?Ans:
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.
Question: 70What is the series of Window Events at Startup in WPF?Ans:
* At application startup, the Window events that are fired (in order) for the main window
are:1) Initialized - Main window is being created2) IsVisibleChanged - IsVisible property
set to true3) SizeChanged - Size property set to size of window4) LayoutUpdated Window layout changes5) SourceInitialized - Window is attached to Win32 window
handle6) Activated - Window becomes foreground window7) PreviewGotKeyboardFocus Window getting focus

WPF Interview Questions & Answers

By Jignesh Patel ([email protected]) Page 148) IsKeyboardFocusWithinChanged IsKeyboardFocusWithin property set to true9) IsKeyboardFocusedChanged IsKeyboardFocused property set to true10) GotKeyboardFocus - Window now has
keyboard focus11) LayoutUpdated - Window layout changes12) Loaded - Window is now laid
out, fully rendered13) ContentRendered - All window content has been rendered
Question: 71What is the series of event fired for application shutdown in WPF?Ans:
1) Closing - Window is going to close2) IsVisibleChanged - IsVisible property set to
false3) Deactivated - Window becomes background window4)
IsKeyboardFocusWithinChanged - IsKeyboardFocusWithin property set to false5)
IsKeyboardFocusedChanged - IsKeyboardFocused property set to false6)
LostKeyboardFocus - Window no longer has keyboard focus7) Closed - Window is closing
Question: 72How to Creating Windows Forms Controls Dynamically in WPF?Ans:
1) Import the following namespaces:using System.Windows.Forms;using
System.Windows.Forms.Integration;2) Create the windows forms control and set its
properties and event handlers.3) Add the control to the 'Child' property of
'WindowsFormsHost' object.4) Add the host object to the 'Children' collection of the
panel.
Question: 73How to host WPF Controls in Windows Forms?Ans:
1) Add reference to the following:a) Presentation Coreb) Presentation Frameworkc)
WindowsBased) WindowsFormsIntegratione) System.Xaml2) Also add reference to the
WPF control DLL.3) Use the 'ElementHost' control in 'WPF Interoperability' tab in
Toolbox to host WPF controls.

WPF Interview Questions & Answers

By Jignesh Patel ([email protected]) Page 15


Question: 74Logical Tree Vs Visual TreeAns:
Elements of a WPF user interface are hierarchically related. This relation is called
the LogicalTree. Thetemplate of one element consists of multiple visual elements. This
tree is called the VisualTree. WPFdiffers between those two trees, because for some
problems you only need the logical elements and forother problems you want all elements.
<Window><Grid><Label Content="Label" /><Button Content="Button" /></Grid></Window>
Question: 75
Why do we need two different kinds of trees?Ans:

A WPF control consists of multiple, more primitive controls. A button - for example
- consists of aborder, a rectangle and a content presenter. These controls are visual
children of the button.When WPF renders the button, the element itself has no
appearance, but it iterates through the visualtree and renders the visual children of it.
This hierarchical relation can also be used to do hit-testing,layout etc.But sometimes you
are not interested in the borders and rectangles of a controls' template.
Particularlybecause the template can be replaced, and so you should not relate on the
visual tree structure!Because of that you want a more robust tree that only contains the
"real" controls - and not all thetemplate parts. And that is the eligibility for the logical
tree.

Activity (4)

FILTERS
Add to collectionReviewAdd NoteLike
1 hundred reads
1 thousand reads
nats007 liked this
Mohit Agarwal liked this
Download and

You might also like