Home »
MCQs
XAML MCQs (Multiple-Choice Questions)
Practice these XAML MCQs (Multiple-Choice Questions) with answers and explanations to test your knowledge of Extensible Application Markup Language, XAML syntax, namespaces, object elements, properties, markup extensions, resources, events, data binding, and WPF application development.
XAML MCQs
These XAML multiple-choice questions cover fundamental and advanced concepts used when creating user interfaces and defining objects in XAML-based applications.
List of XAML MCQs
Below is the list of XAML MCQs with answers and explanations.
1. What does XAML stand for?
- Extensible Application Markup Language
- Extended Application Modeling Language
- Extensible Application Modeling Language
- XML Application Markup Language
Answer: A) Extensible Application Markup Language
Explanation:
XAML stands for Extensible Application Markup Language. It is a declarative markup language used to define objects, properties, UI elements, resources, and other application structures.
2. What type of language is XAML?
- Procedural programming language
- Declarative markup language
- Database query language
- Assembly language
Answer: B) Declarative markup language
Explanation:
XAML is a declarative markup language. Instead of describing every programming step, it describes objects, their properties, relationships, and other application structures.
3. Which file extension is normally associated with XAML files?
- .xmlx
- .xaml
- .xui
- .markup
Answer: B) .xaml
Explanation:
XAML files normally use the .xaml extension. In WPF applications, these files commonly contain the declarative definition of the user interface.
4. Which technology commonly uses XAML to define the user interface of Windows desktop applications?
- ASP.NET Web Forms
- WPF
- ADO.NET
- ADO
Answer: B) WPF
Explanation:
Windows Presentation Foundation (WPF) uses XAML extensively to declaratively define windows, controls, layouts, resources, styles, and other UI elements.
5. What does an object element in XAML generally represent?
- A database record
- An instance of a type
- A compiler directive
- A CSS selector
Answer: B) An instance of a type
Explanation:
A XAML object element generally represents an instance of a type. For example, <Button> represents a Button object in a WPF XAML document.
6. Which syntax represents a self-closing XAML element?
- <Button></Button>
- <Button/>
- <Button>/<Button>
- </Button>
Answer: B) <Button/>
Explanation:
A self-closing XAML object element uses the /> syntax. It is useful when the element has no nested content.
7. Which syntax is used to set a property directly as an attribute in XAML?
- Property:Value
- Property="Value"
- [Property]=Value
- Property:=Value
Answer: B) Property="Value"
Explanation:
Attribute syntax in XAML uses the property name followed by an equals sign and a quoted value, such as Width="200".
8. Which XAML syntax is used when a property needs a nested object definition?
- Property element syntax
- Event-only syntax
- Namespace syntax
- Comment syntax
Answer: A) Property element syntax
Explanation:
Property element syntax represents a property using a nested XML element, such as <Button.Background>. It is useful when the property's value requires a more complex object definition.
9. Which syntax correctly sets the Margin property using property element syntax?
- <Button.Margin><Thickness/></Button.Margin>
- <Button-Margin></Button-Margin>
- <Button Margin.Element></Button>
- <Margin.Button></Margin.Button>
Answer: A) <Button.Margin><Thickness/></Button.Margin>
Explanation:
Property element syntax uses the form <Type.Property>. A complex value can then be declared inside that property element.
10. Is XAML generally case-sensitive?
- Yes
- No
- Only on Linux
- Only for attributes
Answer: A) Yes
Explanation:
XAML is generally case-sensitive. Object elements, property names, attribute names, and XAML language constructs must use the appropriate casing when referring to their underlying types or members.
11. Which attribute defines the default XML namespace in a typical WPF XAML file?
- namespace
- xmlns
- x:namespace
- xml:default
Answer: B) xmlns
Explanation:
The xmlns attribute defines an XML namespace. In typical WPF XAML, it maps the default namespace to the WPF presentation namespace.
12. What does the x: prefix commonly represent in WPF XAML?
- The XAML language namespace
- The XML database namespace
- The application database namespace
- The CSS namespace
Answer: A) The XAML language namespace
Explanation:
The x: prefix is commonly mapped to the XAML language namespace and provides constructs such as x:Class, x:Key, x:Name, and x:Type.
13. Which attribute connects a XAML root element with its code-behind class in WPF?
- x:Class
- x:Code
- x:Backend
- x:TypeClass
Answer: A) x:Class
Explanation:
The x:Class attribute specifies the CLR namespace and class name associated with a XAML file's code-behind class in the WPF programming model.
14. Which XAML directive assigns a key to an object stored in a resource dictionary?
- x:Id
- x:Key
- x:Resource
- x:DictionaryKey
Answer: B) x:Key
Explanation:
x:Key assigns a unique key to a resource so that it can later be referenced from XAML.
15. Which XAML directive is commonly used to give a runtime name to an object?
- x:Name
- x:ObjectName
- x:Id
- x:ReferenceName
Answer: A) x:Name
Explanation:
x:Name gives a XAML-created object a name that can be used to reference the object at runtime. In WPF, many framework elements also expose a regular Name property.
16. Which XAML directive specifies a type reference?
- x:Type
- x:Class
- x:Reference
- x:Object
Answer: A) x:Type
Explanation:
x:Type constructs a Type reference from a type name. It can be used when a XAML property expects a Type value.
17. Which markup extension is commonly used for data binding in WPF XAML?
- {Data}
- {Binding}
- {BindObject}
- {Connect}
Answer: B) {Binding}
Explanation:
The {Binding} markup extension is used to create data binding expressions in WPF XAML.
18. Which markup extension is commonly used to reference a resource that is resolved when the XAML is loaded?
- {StaticResource}
- {StaticObject}
- {ResourceStatic}
- {LoadResource}
Answer: A) {StaticResource}
Explanation:
{StaticResource} references an object stored in a resource dictionary and is resolved when the XAML is loaded.
19. Which markup extension allows a resource reference to be reevaluated at runtime?
- {RuntimeResource}
- {DynamicResource}
- {LiveResource}
- {RefreshResource}
Answer: B) {DynamicResource}
Explanation:
{DynamicResource} creates a dynamic resource reference, allowing WPF to reevaluate the resource when the applicable resource value changes.
20. What do curly braces such as {Binding} indicate in XAML attribute values?
- A comment
- A markup extension
- An XML declaration
- A namespace declaration
Answer: B) A markup extension
Explanation:
Curly braces in a XAML attribute value indicate markup extension usage. Markup extensions provide values through special XAML processing rather than ordinary string conversion.
21. Which XAML markup extension can reference a static member?
- {x:Static}
- {x:StaticMember}
- {StaticValue}
- {x:Member}
Answer: A) {x:Static}
Explanation:
{x:Static} enables XAML to reference a static value that is otherwise not directly available through ordinary XAML property syntax.
22. Which markup extension can create a Type reference in XAML?
- {x:Type}
- {x:ObjectType}
- {TypeReference}
- {x:ClassType}
Answer: A) {x:Type}
Explanation:
{x:Type} creates a Type reference based on a type name. It is useful for properties such as those that expect a Type value.
23. How many root elements can a well-formed XAML document have?
- One
- Two
- Three
- Unlimited
Answer: A) One
Explanation:
A XAML file must have one root element so that it forms a well-formed XML document and a valid XAML document.
24. Which namespace is typically used as the default WPF presentation namespace?
- http://schemas.microsoft.com/winfx/2006/xaml/presentation
- http://schemas.microsoft.com/wpf/default
- http://schemas.microsoft.com/xaml/wpf
- http://schemas.microsoft.com/dotnet/wpf
Answer: A) http://schemas.microsoft.com/winfx/2006/xaml/presentation
Explanation:
This namespace is typically declared as the default XAML namespace in WPF files and provides access to WPF presentation types used in markup.
25. Which namespace is commonly mapped to the x: prefix in WPF XAML?
- http://schemas.microsoft.com/winfx/2006/xaml
- http://schemas.microsoft.com/xaml/x
- http://schemas.microsoft.com/wpf/xaml-language
- http://schemas.microsoft.com/dotnet/xaml
Answer: A) http://schemas.microsoft.com/winfx/2006/xaml
Explanation:
The x: prefix is conventionally mapped to the XAML language namespace http://schemas.microsoft.com/winfx/2006/xaml.
26. Which XAML syntax is used to declare a custom XML namespace prefix mapped to a CLR namespace?
- xmlns:local="clr-namespace:MyApp"
- namespace:local="MyApp"
- x:local="MyApp"
- clr:local="MyApp"
Answer: A) xmlns:local="clr-namespace:MyApp"
Explanation:
A custom prefix can be mapped to a CLR namespace using the xmlns declaration and the clr-namespace: mapping syntax.
27. Which XAML syntax correctly references a type from a custom namespace mapped to local?
- <local:CustomerControl/>
- <CustomerControl:local/>
- <x:local.CustomerControl/>
- <local.CustomerControl/>
Answer: A) <local:CustomerControl/>
Explanation:
After mapping a namespace to the local prefix, a type from that namespace can be referenced using the local:TypeName form.
28. Which XAML element syntax is used to define a collection property explicitly?
- Property element syntax
- Namespace element syntax
- Collection directive syntax
- Array element syntax only
Answer: A) Property element syntax
Explanation:
Collection properties can be represented explicitly using property element syntax. WPF XAML also supports an optimized collection syntax where child elements are interpreted as collection items.
29. Consider the following XAML. What does Content represent?
<Button Content="Save"/>
- An event handler
- A property value assigned to the Button
- A namespace prefix
- A resource key
Answer: B) A property value assigned to the Button
Explanation:
Content is a property of the Button. The value Save is assigned to that property using XAML attribute syntax.
30. Which XAML feature allows an element to provide its primary content without explicitly naming the content property?
- Content property
- Default namespace
- Type converter
- Attached event
Answer: A) Content property
Explanation:
XAML allows a class to designate one property as its content property. This enables content to be placed directly inside the element without explicitly writing the property element.
31. Which interface or mechanism is commonly used to convert XAML string attribute values into other .NET types?
- Type converter
- Event router
- Resource resolver
- Namespace mapper
Answer: A) Type converter
Explanation:
XAML can use type converters to convert string values from attribute syntax into appropriate .NET property types, such as converting textual values into certain structured objects.
32. Which event attribute syntax is valid in WPF XAML?
- Click="Button_Click"
- event:Click="Button_Click"
- OnClick="Button_Click"
- handler.Click="Button_Click"
Answer: A) Click="Button_Click"
Explanation:
Events can be specified using attribute syntax. For example, Click="Button_Click" associates the Button's Click event with a handler named Button_Click.
33. In WPF, where is a typical event handler referenced by XAML implemented?
- In a CSS file
- In code-behind or another appropriate code class
- Inside ResourceDictionary only
- Inside the XML namespace declaration
Answer: B) In code-behind or another appropriate code class
Explanation:
In typical WPF applications, XAML event attributes reference handlers implemented in the associated code-behind class or another appropriate class structure.
34. Which method is commonly generated or called to initialize a WPF XAML-defined component?
- InitializeComponent()
- InitializeXaml()
- LoadComponentTree()
- BuildUI()
Answer: A) InitializeComponent()
Explanation:
WPF applications commonly use InitializeComponent() to load and initialize the objects and resources defined by the XAML markup for a component.
35. What is the primary purpose of the x:Name value in WPF XAML?
- To identify an object instance at runtime
- To define a database table
- To specify a CSS class
- To assign an XML encoding
Answer: A) To identify an object instance at runtime
Explanation:
x:Name provides an identifier for a XAML-created object so that the object can be referenced by name at runtime within the applicable XAML namescope.
36. What is a XAML namescope used for?
- Managing the uniqueness and lookup of named XAML objects
- Managing SQL queries
- Managing application configuration files
- Managing network ports
Answer: A) Managing the uniqueness and lookup of named XAML objects
Explanation:
A XAML namescope defines the scope in which names assigned to XAML objects are registered and can be resolved.
37. Which XAML construct is commonly used to define reusable resources?
- ResourceDictionary
- ObjectMap
- ResourceClass
- ReusableCollection
Answer: A) ResourceDictionary
Explanation:
A ResourceDictionary stores reusable objects such as brushes, styles, templates, and other resources that can be referenced by key.
38. Which attribute is normally used to assign a key to a resource?
- x:Key
- x:ResourceId
- ResourceKeyName
- Key:x
Answer: A) x:Key
Explanation:
x:Key identifies a resource in a resource dictionary so that it can be retrieved by that key.
39. Which property can be assigned a binding expression such as {Binding Name}?
- A dependency property such as Text
- Only an XML namespace
- Only an event
- Only a resource key
Answer: A) A dependency property such as Text
Explanation:
In WPF, data binding is commonly applied to dependency properties. For example, a TextBlock's Text property can use a binding expression.
40. What does the following XAML binding normally mean?
<TextBlock Text="{Binding Name}"/>
- Set Text to the literal word Name
- Bind Text to the Name property of the binding source
- Bind Text to the XML namespace Name
- Load a resource named Name
Answer: B) Bind Text to the Name property of the binding source
Explanation:
The {Binding Name} expression tells the WPF binding system to obtain the value of the Name property from the applicable binding source.
41. Which XAML feature allows properties to be attached to elements by another class?
- Attached properties
- Static properties
- Namespace properties
- External properties
Answer: A) Attached properties
Explanation:
Attached properties allow a class to define a property that can be set on other elements. A common WPF example is Grid.Row.
42. Which syntax correctly sets the Grid row attached property?
- Row.Grid="1"
- Grid.Row="1"
- GridRow="1"
- x:Grid.Row="1"
Answer: B) Grid.Row="1"
Explanation:
Grid.Row="1" uses attached-property syntax to place an element in row 1 of a WPF Grid.
43. Which class is commonly associated with attached properties in the WPF Grid layout system?
- Grid
- PanelProperties
- LayoutProperties
- GridSettings
Answer: A) Grid
Explanation:
The WPF Grid class defines attached properties such as Grid.Row and Grid.Column to control the placement of child elements.
44. Which XAML element can be used to define a style resource?
- Style
- ThemeObject
- FormatStyle
- ControlStyleDefinition
Answer: A) Style
Explanation:
The WPF Style element defines reusable property settings for controls and other framework elements. Styles can be stored as resources and referenced by key.
45. Which XAML element is used to define a reusable visual structure for a WPF control?
- ControlTemplate
- ControlStyle
- VisualResource
- TemplateResource
Answer: A) ControlTemplate
Explanation:
ControlTemplate defines the visual structure of a control and can be used to customize how a control is rendered while retaining its control behavior.
46. Which XAML element is commonly used to define how data items are visually displayed?
- DataTemplate
- DataStyle
- ItemRenderer
- DataView
Answer: A) DataTemplate
Explanation:
A DataTemplate defines the visual representation of a data object, commonly when displaying items in controls such as ListBox or ListView.
47. Which statement about XAML comments is correct?
- They use the XML comment syntax
- They use // only
- They use /* */ only
- They require the x:Comment directive
Answer: A) They use the XML comment syntax
Explanation:
XAML uses XML syntax, so comments can be written using <!-- comment -->.
48. Which class can be used to load XAML dynamically from code in WPF?
- XamlReader
- XamlLoaderOnly
- MarkupReader
- XmlUIReader
Answer: A) XamlReader
Explanation:
The WPF XamlReader class provides functionality for reading and loading XAML. Its Load method can create an object tree from XAML input.
49. Consider the following XAML. What does the x:Class attribute identify?
<Window x:Class="MyApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
</Window>
- The CSS class
- The CLR class associated with the XAML
- The resource dictionary key
- The XML document type
Answer: B) The CLR class associated with the XAML
Explanation:
The x:Class attribute specifies the fully qualified CLR class name associated with the XAML file. In a typical WPF project, this connects the XAML markup with its code-behind class.
50. Consider the following XAML. What value will the TextBlock display if the Window's DataContext contains a property named UserName whose value is Sudhir?
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<TextBlock Text="{Binding UserName}"/>
</Window>
- UserName
- Text
- Sudhir
- The binding expression itself
Answer: C) Sudhir
Explanation:
The Text property uses the {Binding UserName} expression. The TextBlock inherits the Window's DataContext, so the binding retrieves the value of the UserName property. If that value is Sudhir, the TextBlock displays Sudhir.
Advertisement
Advertisement