WPF Interview Questions and Answers
Question - 101 : - What are the various X: prefix used in XAML language?
Answer - 101 : -
- x: Key à It sets a unique key for each resource in a Resource Dictionary
- x: Classà It specifies the CLR ( Common Language Runtime) namespace and class name for the class that provides code
- x: Name à It specifies a run-time object name for the instance that exist in run time code after an object element is processed
- x: Static à It enables a reference that returns a static value which otherwise an XAML compatible property
- x: Type à It constructs a Type reference based on the type name
Question - 102 : - What is Xaml Namespace?
Answer - 102 : -
Namespace can be defined as an environment or an abstract container used to hold a logical grouping of unique identifiers or symbols.
Question - 103 : - How custom classes used in XAML can be defined?
Answer - 103 : -
Custom classes are used in two ways
- With the code that produces the Primary Windows Presentation Foundation (WPF) application or within the code behind
- In a separate assembly as a class, such as an executable or DLL used as a class library
Question - 104 : - Explain what is the use of property element syntax?
Answer - 104 : -
With the help of property element syntax, you can add children element with a name in the form of parent.propertyName.
Question - 105 : - Explain how you can display different data at run time and design time?
Answer - 105 : -
- One way of displaying data at run time and design time is to declare your data in XAML.
- Another way of doing it is by declaring it in XAML by using various data attributes from the designer XML namespace. With a d: prefix, this namespace is typically declared.
Question - 106 : - What is data binding with XAML?
Answer - 106 : -
Data binding provides a simple way to display and interact with data. An example will show how you can do data binding in XAML. The binding in XAML is done by using {binding….} syntax.
Question - 107 : - What should a root element of an XAML document contain?
Answer - 107 : -
In XAML document, the root element consists only certain elements, and these elements are Window, a Canvas or panels.
Question - 108 : - What are the ways you can declare objects in XAML?
Answer - 108 : -
To declare objects in XAML, there are three ways
- Directly, using object element syntax: This syntax is used to declare root objects or nested objects that set property values
- Indirectly by using attribute syntax: This syntax uses an inline string value which has an instruction on how to create an object. To set the value of the property to a newly created reference, the XAML parser uses this string
- Using a markup extension
Question - 109 : - Explain Object Element Syntax in XAML?
Answer - 109 : -
To instantiate a CLR class or structure by declaring an XML element, an XAML markup syntax is used. This syntax is referred as Object Element Syntax.
Question - 110 : - Explain what is Type Converter?
Answer - 110 : -
The type converter is helpful to convert a string into the appropriate value type where there is no markup extension usage. Type Converter defines four members for converting to and from string for xaml purposes.
- CanConvertTo
- CanConvertFrom
- ConvertTo
- ConvertFrom