WPF Interview Questions

Jun 10, 2009 at 3:34 AM

What should every WPF developer know?

Entry Level

  • Strong .NET 2.0 Background & willing to learn!
  • Explain dependency properties?
  • What's a style?
  • What's a template?
  • Differences between base classes: Visual, UIElement, FrameworkElement, Control
  • Visual vs Logical tree?
  • Property Change NOtification (INotifyPropertyChange and ObservableCollection)
  • ResourceDictionary - Added by a7an
  • UserControls - Added by a7an


  • Routed Events & Commands
  • Binding...?
  • Converters - Added by Artur Carvalho
  • Explain WPF's 2-pass layout engine?
  • How to implement a panel?
  • Interoperability (WPF/WinForms)
  • Blend/Cider - Added by a7an
  • animations and storyboarding
  • ClickOnce Deployment
  • Skinning/Themeing
  • Custom Controls
  • How can worker threads update the UI?


  • Example of attached behaviour?
  • What is PRISM,CAL & CAG?
  • How can worker threads update the UI?
  • WPF 3D - Added by a7an
  • Differences between Silverlight 2 and WPF
  • MVVM/MVP - Added by a7an
  • WPF Performance tuning
  • Pixel Shaders
  • Purpose of Freezables
Jun 10, 2009 at 3:36 AM

Windows Presentation Foundation Interview Questions/FAQs



1. General questions

    1.1 What is WPF?
    1.2 What is XAML?
    1.3 What is XBAP?

2. Concepts Element Tree

    2.1 How can I override the Logical Tree ?
    2.2 How can I enumerate all the descendants of a visual object ?

3. Concepts Dependency Property

    3.1 How can I create Custom Read-Only Dependency Properties ?
    3.2 How can I use Dependency Property MetaData?
    3.3 How can I register the default value of the State dependency property to be false?

4. Concepts Attached Property

    4.1 What is Attached Properties and how to register it?
    4.2 How can I set an attached property in code?

5. Concepts Attached Property

    5.1 What is a Routed event?
    5.2 How can I handle the input event through XAML?

6. Concepts Resources.

    6.1 How can I use an application resource ?

7. Concepts Animation

    7.1 What are the requirements for a property to be animated?
    7.2 How do I trigger an animation when the data in the control is changed?
    7.3 What is Path animation?

8. Concepts Freezable Object

    8.1 What is a Freezable?
    8.2 How can I determine whether a Freezable Is Frozen?
    8.3 How can I obtain a writable copy of a Read-Only Freezable?

9. Concepts Input and Commands.

    9.1 What is Commanding in WPF?
    9.2 How do I create a CommandBinding using a RoutedCommand?
    9.3 How can I add a CommandBinding to a window using markup?

10. Concepts Layouts

    10.1 When I try to add multiple controls to a button it shows an error, how do I add multiple controls to a button?
    10.2 How placing controls in a WrapPanel differs from a Grid?

11. XAML Inline Styles and Templates

    11.1 How can I restrict the use of style ?
    11.2 How can I create an extended style ?
    11.3 How can I set a ControlTemplate ?
    11.4 How can I create a custom WPF button whose look and feel depends on the Windows desktop theme currently in use. How do I get notified when the user changes the theme?
    11.5 What are the limitations of Inline Styles and Templates ?

12. XAML XML Namespaces

    12.1 How can I map CLR Namespaces to XML Namespaces in an Assembly ?
    12.2 Which namespace is used to associate namespace identifiers with element names ? Is there any effect on the attributes ?

13. XAML Code Behind

    13.1 What is the use of x:code ?

14. XAML Custom Class

    14.1 What way can a custom class can be defined in XAML?

15. XAML Type Converters

    15.1 How can I apply the TypeConverter Attribute?

16. Content Model ItemControl

    16.1 How can I create Four Button controls with the contents set to a String, a DateTimeObject, an UIElement and A Panel that contains other UIElement objects?
    16.2 Can I create a ContentTemplate and apply the template to a ContentControl ?

17. Content Model HeaderedItemsControl

    17.1 How can I create a ControlTemplate for a HeaderedItemsControl ?

18. Content Model HeaderedContentControl

    18.1 How can I make a style for a ContentControl so that the control has an enhanced visual appearance ?

19. Content Model Content Control

    19.1 How can I get an enumerator to the ContentControl's logical child elements ?

20 Content Model Decorator Content Model

    20.1 How do I create a Borderless Window in WPF ?
    20.2 How can I animate a BorderThickness value ?
    20.3 How can I use Event Trigger to control a StoryBoard after it is started ?

21 Content Model Panel Content Model

    21.1 How do I add controls to Panel Content Model type of controls?

22 Documents Serialization and Storage

    22.1 How can I store a given document in a specific format using CreateSerializerWriter methods ?
    22.2 How can I use MemoryStream to create a deep clone of a serializable object ?
    22.3 How can I do versioning using Custom Serialization ?

23 Documents Annotations

    23.1 How can I Match Annotations with Annotated Objects ?
    23.2 How can I create an application that is used to declare a Context Menu with routed commands that the users can access to create and manage annotations ?

24 Documents Flow Content

    24.1 How can I define three paragraphs under one section ?
    24.2 How can I use the BlockUIContainer element to host UIElement objects within Flow content ?
    24.3 Can I embed a figure into a paragraph of text ?

25 Documents Printing

    25.1 How can I programmatically print XPS Files ?

26 Graphics and Multimedia Rendering Graphics

    26.1 How can I create a combine hard and soft shadow ?
    26.2 How can I use a DoubleAnimation to rotate the textblock ?
    26.3 What is the order in which the controls are rendered ?
    26.4 How do I enumerate child objects in a visual tree ?
    26.5 How rendering in WPF differs from WIN32 applications?

27 Graphics and Multimedia Animation and Timing

    27.1 When an animation is applied, the property value gets overwritten. How do we prevent the value of property ?
    27.2 Performance gets reduced even after navigating away from a page that contains animation. How do we handle this issue ?
    27.3 How do I apply an animation without using a storyboard ?

28 Graphics and Multimedia 2D Graphics

    28.1 How do I apply BitmapEffect to a particular area of an Image ?
    28.2 How do I apply Transform when an event is occurred ?
    28.3 In what way CombinedGeometry is used ?

29 Graphics and Multimedia 3D Graphics

    29.1 What are the properties that reduce the performance of a 3D graphics ?
    29.2 How lights are useful in 3D graphics ?
    29.3 How do I change the location of a model ?

30 Graphics and Multimedia Visual Layer

    30.1 How HitTest methods in VisualTreeHelper is useful ?
    30.2 How do I use DrawingVisual object ?

31 Control Customization Adorners

    31.1 What is an adorner ?
    31.2 Where can adorners be used ?
    31.3 How to add a custom adorner ?
    31.4 How do I bind an Adorner to an Element ?
    31.5 How do I remove the Adorner from an element ?

32 Control Customization Stylable controls

    32.1 Where can I find information about guidelines to be followed while designing Stylable controls?
    32.2 What are the different models for Control authoring ?

33 Control Customization ControlTemplates

    33.1 What is the use of a ControlTemplate ?
    33.2 How to access elements that are embedded inside the ControlTemplate ?
    33.3 How do I build an ItemsControl ControlTemplate ?
    33.4 How to edit templates using Microsoft Expression Blend ?
    33.5 How to get the default template of a control programmatically ?

34 Data Data Binding

    34.1 How to use binding in XAML ?
    34.2 What is the use of the RelativeSource property ?
    34.3 What is DataContext ? How is it used ?
    34.4 Can ItemControl's Items and ItemsSource properties be modified simultaneously ?
    34.5 How do I filter Items in an ItemControl when the ItemControl's ItemsSource is set to a datasource?
    34.6 What are the uses of BindingModes?
    34.7 How do I update the source as I type in a TextBox?
    34.8 When an XMLDataProvider can be used ? What are it's specific uses ?
    34.9 How does TwoWay BindingMode work in an XMLDataProvider?
    34.10 In what way is an ObjectDataProvider useful?
    34.11 How to pass a parameter to a constructor using ObjectDataProvider ?
    34.12 How to pass a parameter to a function using ObjectDataProvider ?
    34.13 How can I bind a method and pass a parameter to the method ?
    34.14 How to Get or Set a value that indicates whether to include the DataErrorValidationRule ?

35 Data DragandDrop

    35.1 What are the objects involved in DragandDrop?
    35.2 How do I create a DataObject?
    35.3 How do I retrieve data from a DataObject ?

36 Data Serialization

    36.1 What is Serialization ?
    36.2 How to write an IsolatedStorage to an XML file ?
    36.3 How do I serialize objects to a binary file ?

37 Globalization and Localization Attributes

    37.1 What are the three types of Localizability Attributes and how to use them ?
    37.2 How can I set the Language property to the current user's UI language ?
    37.3 How can I set the substitution property by overriding the default substitution ?

38 Globalization and Localization Comments

    38.1 How can I specify in the .proj file whether to leave the free-form localization comments in the assembly using LocalizationDirectivesToLocFile tag ?
    38.2 How can I add localization comments to an XAML file ?

39 Globalization and Localization Globalization Struc

    39.1 Can I override the default categories for platform controls in XAML as well ?
    39.2 How can I automatically layout Grids Using the IsSharedSizeScope Property ?

40 Application and Deployment ClickOnce

    40.1 How does ClickOnce deployment work ?
    40.2 Can I add prerequisites in my ClickOnce deployment ?
    40.3 How do I enable automatic updates for my application using ClickOnce deployment ?

41 Application and Deployment Frame

    41.1 What is the difference between Frame and NavigationWindow ?
    41.2 How does Rendering work in Frame control ?
    41.3 Can I add dynamic HTML content to a Frame control ?

42 Application and Deployment Page

    42.1 Are XAML Browser Applications OS independent ?
    42.2 When I run an XBAP application, I get Application Deployment Error. What do I do to overcome this error ?
    42.3 How to navigate between pages in an application ?

43 Application and Deployment Navigation

    43.1 How to set content of a NavigationWindow ?
    43.2 How do I handle Back and Forward button click ?
    43.3 How do I pass data between pages in a NavigationWindow ?

44 Application and Deployment Setup

    44.1 How do I add registry entries in a setup project ?
    44.2 How do I deploy shared components ?
    44.3 How launch conditions are useful and how to add one to a setup project ?

45 Application and Deployment Window

    45.1 How do I create a child window in WPF ?
    45.2 How do I host Windows Forms control in a WPF Window ?
    45.3 Does WPF support MDI ?

46 Interoperability Message Loops Between

    46.1 How can I write Message Loops ?
    46.2 How can I HwndSource Treats ComponentDispatcher Events ?
    46.3 How can I set the Owner property of the WPF window to the handle of our main form using helper class ?

47 Interoperability Win32 in WPF

    47.1 How can I use Windows Forms in a WPF application ?
    47.2 How do I host a Windows Forms control in a WPF application ?
    47.3 How can I leverage my current investment in Windows Forms applications and still tap into the cool features of WPF ?
    47.4 How can I host a Windows Forms Composite Control in Windows Presentation Foundation ?

48 Interoperability WPF in Win32

    48.1 How do I host a WPF control in a Windows Forms application?
    48.2 How can I Host the WPF UserControl in Windows Forms ?
    48.3 What is the procedure to host the WPF content in Win32 window ?

49 Interoperability Windows Forms and WPF

    49.1 Will you provide a tool to convert Windows Forms applications to WPF applications ?
    49.2 What about user controls and third-party controls including ActiveX controls?
    49.3 Where do I find System.Windows.Forms.Integration ?
    49.4 Can I use a WindowsFormsHost element to host a System.Windows.Forms ?

50 Security Trusted Security

    50.1 How do I assign full trust to an XBAP application ?
    50.2 I am able to access the registry using full trust XBAP application in debug mode, when hosted in an intranet, the application gets crashed. What do I do?
    50.3 How do I get a custom defined permission set of an XBAP application ?

51 Security Partial Trust Security

    51.1 How to get data from database in XBAP application ?
    51.2 Does permission set of partial trust change in the Local Intranet and Internet?
    51.3 How do I detect permission for a file in a partial trust application ?

52 Tools Microsoft Expression Blend

    52.1 Can a WPF application be designed using Microsoft Expression Blend ?
    52.2 How do I add animations using Microsoft Expression Blend ?
    52.3 How do I add custom controls to an application using Microsoft Expression Blend ?

53 Tools ZAM3D

    53.1 What is ZAM3D ?
    53.2 What are the file formats supported by ZAM3D ?
    53.3 Can an XAML file created using ZAM3D be used with Visual Studio.NET ?

54 Tools XAMLPAD

    54.1 What is XAMLPAD ?
    54.2 Does XAMLPAD support custom controls ?
    54.3 Can we see the output of an XAML using XAMLPAD ?

55 Controls ToolTip

    55.1 Can I delay the display of a ToolTip ?
    55.2 How can I use the ToolTipService properties to specify the position of a tooltip whose content is not a ToolTip object ?
    55.3 Can I use the BetweenShowDelay Property ?

56 Controls TextBlock

    56.1 How can I make a TextBlock editable when it is clicked and the value is committed when ESC or ENTER is pressed?

57 Controls TabControl

    57.1 How do I prevent the user from changing the selected tab page in a TabControl ?
    57.2 How do I dynamically hide and unhide tabs in a TabControl ?
    57.3 How do I make the tabs in a TabControl appear on the bottom instead of the right?
    57.4 How can I add a style to a TabItem that is used in the TabControl ?

58 Controls ProgressBar

    58.1 How can I create a ProgressBar and use an animation to simulate the progress of an operation ?
    58.2 How can I make the text changed by itself during progress?

59 Controls PrintDialog

    59.1 How can I create and display a PrintDialog ?
    59.2 How do I display the PrintPreview as a maximized window and control it's zooming ?

60 Controls Popup

    60.1 How can I animate a Popup ?
    60.2 How can I specify a Custom Popup Position ?

61 Controls TextBox

    61.1 How do I format numbers, dates and currencies in a TextBox ?
    61.2 How do I make a TextBox use all upper-case (or lower-case) characters ?
    61.3 How do I support browsing for a text file and reading it into a TextBox?

62 Controls Canvas

    62.1 How can I use the attached properties of Canvas to position child elements ?

63 Controls ComboBox

    63.1 How do I fill a ComboBox with the available fonts ?
    63.2 How do I bind the values of an enum to a ComboBox ?

64 Controls ListBox

    64.1 How do I bind a string array with a ListBox?
    64.2 How do I display items in a ListBox horizontally?

65 Controls StatusBar

    65.1 How do I create custom layout for StatusBar items?

66 Controls ToolBar

    66.1 How do I determine which button in a ToolBar is clicked ?
    66.2 How can I apply a Style to a Menu control on a ToolBar ?
    66.3 When I tab into a toolbar in WPF I can't tab out again ? What can I do to change this tab behavior ?

67 Controls Context Menu

    67.1 How do I make the Context Menu appear only when clicked at certain portions of the Control ?
    67.2 How can I enable a Context Menu on a disabled Control ?
    67.3 How can I create a shared Context Menu ?
    67.4 How do I make the Context Menu to close after a set time interval?

68 Controls Expander

    68.1 How can I create an Expander with a ScrollViewer ?
    68.2 How can I bind the Expander's header element's Width to the ActualWidth of the Expander ?
    68.3 How do I make the Expander button to be justified to the right, rather than the left which is the default ?

69 Controls DocumentViewer

    69.1 How can I replace the style of a DocumentViewer ?
    69.2 How can I extend the style of a DocumentViewer ?
    69.3 How can I DataBind DocumentViewer's Zoom Property to a TextBox ?
    69.4 How to load an XPS document into the DocumentViewer?

70 Controls FlowDocumentReader

    70.1 How can I load an XAML file into a FlowDocumentReader?
    70.2 How can I save the contents of a FlowDocumentReader as an XAML file ?

71 Controls GroupBox

    71.1 How can I create a GroupBox that has a title and a visible border that encloses it's content ?

72 Controls GridSplitter

    72.1 How can I make sure that a GridSplitter Is visible ?
    72.2 How can I create and use a GridLengthConverter Object ?

73 Controls Image

    73.1 How can I convert an Image to grayscale ?
    73.2 How can I crop an Image ?
    73.3 Why does adding images to an ImageList in the Designer cause them to lose their alpha channel ?
    73.4 How to rotate an image ?
    73.5 How do I access / edit the metadata associated with an Image ?
    73.6 How can the DrawVisual be used for rendering images ?

74 Controls Menu

    74.1 How do I enable the mnemonics (underlines) being displayed when an application is launched ?
    74.2 How can I style a Separator used as a Menu Item ?

75 Controls ScrollBar

    75.1 How can I use the member values of the enumeration to set the HorizontalScrollBarVisibility property of the ScrollViewer control ?
    75.2 How can I use the Content-Scrolling Methods of ScrollViewer ?

76 Controls Slider

    76.1 How can I customize the Ticks on a Slider ?
    76.2 Can I bind two sliders in two different windows ?

77 Controls RichTextBox

    77.1 How do I add a hyperlink to a RichTextBox control ?
    77.2 How do I create and save a RichTextFormat (RTF) file?
    77.3 How do I support drag-and-drop for a RichTextBox?
    77.4 How can I Save, Load, and Print RichTextBox Content ?

78 Controls Border

    78.1 How can I animate the thickness of a border by using ThicknessAnimation ?
    78.2 How can I use a BulletDecorator control that uses an image as the Bullet and a non-text element as the Child ?

79 Controls Border

    79.1 How do I change the shape of the button to an ellipse?
Jun 10, 2009 at 3:38 AM
Q: When should I use WPF instead of DirectX? (Is DirectX dead?)

DirectX is definitely not dead and is still more appropriate than WPF for advanced developers writing hard-core “twitch games” or applications with complex 3D models where you need maximum performance. That said, it’s easy to write a naive DirectX application that performs far worse than a similar WPF application.
DirectX is a low-level interface to the graphics hardware that exposes all of the quirks of
whatever GPU a particular computer has. DirectX can be thought of as assembly language in
the world of graphics: You can do anything the GPU supports.
WPF provides a high-level abstraction that takes a description of your scene and
figures out the best way to render it, given the hardware resources available. Internally, this
might involve using Shader Model 3.0, or the fixed-function pipeline, or software. (Don’t worry if you’re not familiar with these terms, but take it as a sign that you should be using WPF!).
The downside of choosing DirectX over WPF is a potentially astronomical increase in development cost. A large part of this cost is the requirement to test your application on each
driver/GPU combination you intend to support. One of the major benefits of building on top of WPF is that Microsoft has already done this testing for you! You can instead focus your
testing on low-end hardware for measuring performance. The fact that WPF applications can
even leverage the client GPU over Remote Desktop or in a partial-trust environment is also a
compelling differentiator.

Q: When should I use WPF instead of Windows Forms?(Is Windows Forms dead?)

WPF is clearly more suitable for applications with rich media, but some people have said that Windows Forms is the best choice for business applications with traditional user interfaces. I think this belief is based on first versions of WPF in which many standard controls didn’t exist (such as TreeView, ListView, and OpenFileDialog) and a visual designer didn’t exist, making traditional Windows application development in WPF harder than in Windows Forms. Although Windows Forms still has useful controls that WPF lacks (such as DataGridView and PropertyGrid) and at the time of writing has a larger set of third-party controls in the marketplace, WPF has compelling features even for traditional user interfaces (such as the support for resolution independence or advanced layout).

Q: When should I use WPF instead of Adobe Flash?

For creating rich web content, Flash is currently the most popular option because of its ubiquity.
You can put Flash-based content on a website with confidence that the overwhelming
majority of visitors already have the necessary player installed. (And if they don’t, it’s a very
quick download.)
WPF applications can also run within a web browser. WPF has the advantage of better development
tools and programming model, a richer feature set, robust control reuse, broad
programming language support, and full access to the underlying platform (when security
permits). But viewing such content requires Windows and the .NET Framework 3.0 (installed
by default on Windows Vista or later).

Q: How do I get a ToolTip to appear when hovering over a disabled element?
<font face="FranklinGothic-Book" size="1"><font face="FranklinGothic-Book" size="1">

use the

<font face="FranklinGothic-Book" size="1">



ShowOnDisabled attached property of the ToolTipService class! From

XAML, this would look like the following on a Button:

<Button ToolTipService.ShowOnDisabled=”True”>


Or from C# code, you can call the static method corresponding to the attached property:

ToolTipService.SetShowOnDisabled(myButton, true);

Q: How can I forcibly close a ToolTip that is currently showing?
<font face="FranklinGothic-Book" size="1"><font face="FranklinGothic-Book" size="1">

Set its IsOpen property to false.

<font face="FranklinGothic-Book" size="1">



Q: What’s the difference between ComboBox’s IsEditable and IsReadOnly properties?

Setting IsEditable to true turns ComboBox’s selection box into a text box. IsReadOnly controls whether that text box can be edited, just like TextBox’s IsReadOnly property. This means that IsReadOnly is meaningless unless IsEditable is true, and IsEditable being true doesn’t necessarily mean that the selection text can be edited. Below in the table sums up the behavior of ComboBox based on the values of these two properties.

The Behavior for All Combinations of IsEditable and IsReadOnly






The selection box displays a visual copy of the selected item and it doesn’t allow the typing of arbitrary text. (The default behavior.)



Same as above.

true false

The selection box displays a textual representation of the selected item and it allows the typing of arbitrary text.

true true

The selection box displays a textual representation of the selected item but it doesn’t allow the typing of arbitrary text.

Q: When the SelectionChanged event gets raised, how do I get the new selection?

The SelectionChanged event is designed to handle controls that allow multiple selections,
so it can be a little confusing for a single-selection selector such as ComboBox. The
SelectionChangedEventArgs type passed to event handlers has two properties of type
IList: AddedItems and RemovedItems. AddedItems contains the new selection and
RemovedItems contains the previous selection.

void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
if (e.AddedItems.Count > 0)
object newSelection = e.AddedItems[0];
Like this code, never assume that there’s a selected item! Besides the fact that ComboBox’s
selection can be cleared programmatically, it can get cleared by the user when IsEditable is
true and IsReadOnly is false. In this case, if the user changes the selection box text to
something that doesn’t match any item, the SelectionChanged event is raised with an
empty AddedItems collection.

Q: Why should I bother wrapping items in a ComboBoxItem?

ComboBoxItem exposes some useful properties—IsSelected and IsHighlighted—and
useful events—Selected and Unselected. Using ComboBoxItem also avoids a quirky behavior with showing content controls in the selection box (when IsEditable is false): If an item in a ComboBox is a content control, the entire control doesn’t get displayed in the selection box. Instead, the inner content is extracted and shown. By using ComboBoxItem as the outermost content control, the inner content is now the entire control that you probably wanted to be displayed in the first place.
Because ComboBoxItem is a content control, it is also handy for adding simple strings to a
ComboBox (rather than using something like TextBlock or Label).

Q: How can I make ListBox arrange its items horizontally instead of vertically?
<font face="Tahoma" size="2">

One way is to define a new control template, but all


ItemsControls provide a shortcut with its ItemsPanel property. ItemsPanel enables you to swap out the panel used to arrange items while leaving everything else about the control intact. ListBox uses a panel called VirtualizingStackPanel to arrange its items vertically, but the following code replaces it with a new VirtualizingStackPanel that explicitly sets its Orientation to Horizontal:




<VirtualizingStackPanel Orientation=”Horizontal/>




The translation of this XAML to procedural code is not straightforward, but here’s how you

can accomplish the same task in C#:

FrameworkElementFactory panelFactory =

new FrameworkElementFactory(typeof(VirtualizingStackPanel));



myListBox.ItemsPanel = new ItemsPanelTemplate(panelFactory);

Q: How can I get ListBox to scroll smoothly?

By default, ListBox scrolls on an item-by-item basis. Because the scrolling is based on each
item’s height, it can look quite choppy if you have large items. If you want smooth scrolling,
such that each scrolling action shifts the items by a small number of pixels regardless of
their heights, the easiest solution is to set the ScrollViewer.CanContentScroll attached
property to false on the ListBox.
Be aware, however, that by making this change you lose ListBox’s virtualization functionality.
Virtualization refers to the optimization of creating child elements only when they become
visible on the screen. Virtualization is only possible when using data binding to fill the
control’s items, so setting CanContentScroll to false can negatively impact the performance
of data-bound scenarios only.

Q: How can I sort items in a ListBox (or any other ItemsControl)?

Sorting can be done via a mechanism on the ItemsCollection object, so it applies equally to all ItemsControls. ItemsCollection has a SortDescriptions property that can hold any number of System.ComponentModel.SortDescription instances. Each SortDescription describes which property of the items should be used for sorting and whether the sort is ascending or descending. For example, the following code sorts a bunch of ContentControl items based on their Content property:

// Clear any existing sorting first


// Sort by the Content property


new SortDescription(“Content”, ListSortDirection.Ascending));

Q: How do I get the items in my ItemsControl to have Automation IDs, as seen in tools like UISpy?

The easiest way to give any FrameworkElement an Automation ID is to set its Name property, as that gets used by default for automation purposes. However, if you want to give an element an ID that is different from its name, simply set the AutomationProperties.AutomationID attached property (from the System.Windows.Automation namespace) to the desired string.

Q: How can I get items in a StatusBar to grow proportionally?

It’s common to want StatusBar panes that remain proportionately sized. For example,
perhaps you want a left pane that occupies 25% of the StatusBar’s width and a right pane
that occupies 75% of the width. This can be done by overriding StatusBar’s ItemsPanel with
a Grid and configuring the Grid’s columns appropriately.

Q: How can I make TextBox support multiple lines of text?

Setting AcceptsReturn to true allows users to press the Enter key to create a new line of
text. Note that TextBox always supports multiple lines of text programmatically. If its Text is
set to a string containing NewLine characters, it displays the multiple lines regardless of the
value of AcceptsReturn. Also, the multiline support is completely independent from text
wrapping. Text wrapping only applies to individual lines of text that are wider than the

Q: What unit of measurement is used by WPF?

All absolute measurements, such as the numbers used in this section’s size-related properties,
are specified in device-independent pixels. These “logical pixels” are meant to represent
1/96th of an inch, regardless of the screen’s DPI setting. Note that device-independent
pixels are always specified as double values, so they can be fractional.
The exact measurement of 1/96th of an inch isn’t important, although it was chosen
because on a typical 96 DPI display, one device-independent pixel is identical to one physical
pixel. Of course, the notion of a true “inch” depends on the physical display device. If an
application draws a one-inch line on my laptop screen, that line will certainly be longer than
one inch if I hook up my laptop to a projector!

Q: Where’s the entry point in WPF application?

When you create a WPF Windows Application in Visual Studio, the generated project has no Main method, yet it still runs as expected! In fact, even attempting to add a Main method
gives a compilation error telling you that it is already defined.
Application is special-cased when it is compiled from XAML, because Visual Studio assigns
the XAML file a Build Action of ApplicationDefinition. This causes a Main method to be

Q: How do I retrieve command-line arguments in my WPF application?

Command-line arguments are typically retrieved via a string array parameter passed to Main,
but the common way to define WPF applications doesn’t allow you to implement the Main
method. You can get around this in two different ways. One way is to forego defining an
Application-derived class in XAML, so you can manually define the Main method with a
string array parameter. The easier way, however, is to simply call
System.Environment.GetCommandLineArgs at any point in your application, which returns
the same string array you’d get inside Main.

Q: What is BAML?

BAML, which stands for Binary Application Markup Language, is simply XAML that has been parsed, tokenized, and converted into binary form. Although any chunk of XAML can be represented by procedural code, the XAML-to-BAML compilation process does not generate procedural source code. So, BAML is not like Microsoft intermediate language (MSIL); it is a compressed declarative format that is faster to load and parse (and smaller in size) than plain XAML. BAML is just an implementation detail of the XAML compilation process without any direct public exposure, so it could be replaced with something  different in the future. Nevertheless, it’s interesting to be aware of its existence.

Q: Can BAML be decompiled back into XAML?

Sure, because an instance of any public .NET class can be serialized as XAML, regardless of
how it was originally declared. The first step is to retrieve an instance that you want to be the
root. If you don’t already have this object, you can call the static
System.Windows.Application.LoadComponent method as follows:
System.Uri uri = new System.Uri(“MyWindow.xaml”, System.UriKind.Relative);
Window window = (Window)Application.LoadComponent(uri);
This differs from previous code that uses FileStream to load a .xaml file because with
LoadComponent, the name specified as the Uniform Resource Identifier (URI) does not have
to physically exist as a standalone .xaml file. LoadComponent can automatically retrieve
BAML embedded as a resource when given the appropriate URI (which, by MSBuild convention,
is the name of the original XAML source file). In fact, Visual Studio’s autogenerated
InitializeComponent method calls Application.LoadComponent to load embedded BAML,
although it uses a different overload.
After you’ve gotten a hold of the root element instance, you can use the
System.Windows.Markup.XamlWriter class to get a XAML representation of the root
element (and, therefore, any of its children). XamlWriter contains five overloads of a static
Save method, the simplest of which accepts an object instance and returns appropriate
XAML as a string. For example:
string xaml = XamlWriter.Save(window);
It might sound a little troubling that BAML can be so easily “cracked open,” but it’s really no
different from any other software running locally or displaying UI locally. (For example, you can
easily dig into a website’s HTML, JavaScript, and Cascading Style Sheets [CSS] files.)

Q: What are possible ways to implement distributed applications in .NET?

.NET Remoting and ASP.NET Web Services.

Q: Can you create Windows Service Using WPF?

No, you can not build the windows Services using WPF. WPF is presentation technolgy, where as Windows service requires certain permission to perform the certain GUI retalted operations.
If the Windows service does not have the appropriate permissions, there may be unexpected results.

Q: What is WPF?

Windows Presentation Foundation (WPF) is a next-generation presentation system for building Windows client applications with visually stunning user experiences. With WPF, you can create a wide range of both standalone and browser-hosted applications.

Q: What is XAML?

XAML is used extensively in .NET Framework 3.0 technologies, particularly in Windows Presentation Foundation (WPF) . In WPF, XAML is used as a user interface markup language to define UI elements, data binding, eventing, and other features. In WF, workflows can be defined using XAML.

XAML elements map directly to common language runtime object instances, while XAML attributes map to Common Language Runtime properties and events on those objects. XAML files can be created and edited with visual design tools such as Microsoft Expression Blend, Microsoft Visual Studio, and the hostable Windows Workflow Foundation visual designer.

Q: What is XBAP?

XBAP stands for XAML Browser Application. XBAP allows for WPF applications to be used inside a browser. The .NET framework is required to be installed on the client system. Hosted applications run in a partial trust sandbox environment. They are not given full access to the computer's resources and not all of WPF functionality is available.
<font face="StoneSerif" size="1"><font face="StoneSerif" size="1">

WPF supports the creation of applications that run directly in a web browser. (So will WPF/E, when it is released.) They are called XAML Browser Applications (XBAPs), and have a

<font face="StoneSerif" size="1">



.xbap file extension.

The power of this WPF support is that the exact same programming model is used for a XAML Browser Application as for a standard Windows application. Therefore, creating an XBAP isn’t much different than creating a standard Windows application. The main differences are as follows:

. Not all features in WPF or the .NET Framework are accessible (by default).

. Navigation is integrated into the browser (for Internet Explorer 7 or later).

. Deployment is handled differently.

Q: What is a Routed event?
In a typical WPF application, it contains many elements. These elements exist in an element tree relationship with each other. A routed event is a type of event that can invoke handlers on multiple listeners in an element tree, rather than just on the object that raised the event.