WPF Interview Questions and Answers
by Siyamala B, on Apr 6, 2018 12:42:33 PM
Q1. What is meant by WPF?
Ans: 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
Q2. What is Data Binding in WPF
Ans: Data Biding in WPF is a way how the data is communicating between the source and target. It is simply updating the data in view(application UI) with respect to data in the view model(presentation logic) and vice versa.
Q3. What is Converter in WPF ?
Ans: Converter are used in Data Binding. Converters are used when the source and target types are different, or when the target must have a different value than that of the source.
Q4.What are Templates present in WPF ?
Ans: WPF allows you to completely change the visual appearance of a control and representation or Structure of data. Templates in WPF allow you to fully change the UI of anything.
There are two types of Templates in WPF:
1. Data Template
2. Control Template
Q5.What are Triggers in WPF ?
Ans: A Trigger sets properties or starts actions, such as animation, when a property value changes or when an event is raised. Triggers are used in styles to perform some actions. Triggers create visual effects on controls. By using Triggers we can change the appearance of Framework Elements.
There are three types of Triggers available.
1. Property Trigger
2. Event Trigger
3. Data Trigger
Q6.What is Style in WPF ?
Ans: As the name tells it is a way to customize or personalize the look or appearance of objects. A style is a collection of values which represents properties of a specified control. We can assign certain set of styles collectively for a specific type of control ( like all buttons, all textboxes etc) or restrict the style to be used only by those controls which you want explicitly with the help of keys(x:key).
Q7. What is Dependency Property in WPF ?
Ans: WPF introduces a new property called Dependency Property or shortly you may like to call it as DP. Dependency Property comes with some enhanced features in addition to normal CLR Properties.A lot of features come with DP. A Dependency Property is a Property whose value depends on the external sources, such as animations, data bindings, styles, or visual tree inheritance. Not only this, but a Dependency Property also has changed, data binding and styling.
One important thing to keep in mind is that Dependency Properties are declared as static. Because Dependency Property is maintained and declared at class level. All the objects of the class use the single property declared on class level instead of using individually.
Q8. What is the Data Binding Modes in WPF ?
Ans: It is a property of Binding class which is set during the binding indicates the direction of the data flow.
Four type of Modes are there in WPF. They are:
- OneWay : Target is updated when source changes
- TwoWay : Target is updated when the source changes, and similarly, the source is updated when the target changes.
- OneWayToSource : Only the source is updated when the target changes.
- OneTime : Target is updated only the first time the source changes.
Q9. What is XBAP?
Ans: 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.
Q10. What is BAML?
Ans: 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
Q11. What are possible ways to implement distributed applications in .NET?
Ans: There are 2 possible ways to implement distributed applications in .NET,
- .NET Remoting
- ASP.NET Web Services
Q12. What is the difference between xmlns and xmlns:x in WPF ?
Ans: Bothe namespaces helps to define / resolved XAML UI elements.
The first namespace is the default namespace and helps to resolve overall WPF elements.
Hide Copy Code
The second namespace is prefixed by “x:” and helps to resolve XAML language definition.
Hide Copy Code
For instance for the below XAML snippet , we have two things one is the “StackPanel” and the other is “x:name”. “StackPanel” is resolved by the default namespace and the “x:name” is resolved by using “xmlns:x” namespace.
Hide Copy Code
<StackPanel x:Name="myStack" />
Q13. What is XAML in WPF and why do we need it?
Ans: XAML is a XML file which represents your WPF UI. The whole point of creating the UI representation in XML was write once and run it anywhere. So the same XAML UI can be rendered as windows application with WPF and the same UI can be displayed on the browser using WPF browser or Silverlight application.
Q14. How can I create Custom Read-Only Dependecy Properties?
Ans: The typical reason for specifying a read-only dependency property is that these are the properties that is used to determine the state, but where the state is defined in a multitude of factors. A typical example for a read-only property is IsMouseHover
This example shows how to 'register' an attached property as read-only. You can use dependency properties on any 'DependencyObject' types.
public static readonly DependencyProperty IsBubbleSourceProperty = DependencyProperty.RegisterReadOnly(
new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender)
Q15. How can I enumerate all the descendants of a visual object?
Ans: You can enumerate all the descendants of a visual object as follows :
// Enumerate all the descendants of the visual object.
static public void EnumVisual(Visual myVisual)
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(myVisual); i++)
// Retrieve child visual at specified index value.
Visual childVisual = (Visual)VisualTreeHelper.GetChild(myVisual, i);
// Do processing of the child visual object.
// Enumerate children of the child visual object.