Visual Programming MCQs with Answers
Practice important Visual Programming MCQs with answers and explanations.
Chapter: 13
Q301:
What does the XAML <Button xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Content="OK"/> correspond to in C#?
A. System.Windows.Controls.Button b = new System.Windows.Controls.Button(); b.Content = "OK";
B. System.Windows.Controls.Button b = new System.Windows.Controls.Button(); b.Content = "OK"; b.Click += new System.Windows.RoutedEventHandler(button_Click);
C. System.Windows.Controls.Button b = new System.Windows.Controls.Button(); b.Content = "OK";
D. System.Windows.Controls.Button b = new System.Windows.Controls.Button(); b.Click += new System.Windows.RoutedEventHandler(button_Click); b.Content = "OK";
Correct Answer:
A
Chapter: 13
Q302:
What is the purpose of the xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" declaration in XAML?
A. To define the XAML language namespace for special directives
B. To map .NET types to XML namespaces
C. To set the background color of an element
D. To specify a default constructor for an object
Correct Answer:
A
Chapter: 13
Q303:
How does an object element in XAML differ from a property element?
A. An object element has attributes; a property element does not
B. A property element can contain child elements; an object element cannot
C. An object element initializes .NET objects; a property element sets properties
D. A property element initializes .NET objects; an object element sets properties
Correct Answer:
C
Chapter: 13
Q304:
What does the <Button.Background><SolidColorBrush Color="White"/></Button.Background> XAML code represent?
A. Setting the button's background color using a brush converter
B. Setting the button's background color directly in C#
C. Setting the button's background using a markup extension
D. Defining a type converter for the button's background color
Correct Answer:
A
Chapter: 13
Q305:
What does the XAML <Button Content="{Binding Path=Height, RelativeSource={RelativeSource Mode=Self}}"/> do?
A. Binds the button's content to its own height property
B. Sets the button's content to a static value
C. Applies a custom markup extension to the button's content
D. Sets the button's content to the height of another control
Correct Answer:
A
Chapter: 13
Q306:
How are property elements in XAML typically identified?
A. By the period (.) in their syntax
B. By using x: prefix for attributes
C. By being wrapped in curly braces ({})
D. By not having attributes except x:uid
Correct Answer:
A
Chapter: 13
Q307:
What is a primary use of type converters in XAML?
A. To convert string values to corresponding data types
B. To define the layout of XAML elements
C. To bind data from external sources
D. To add custom attributes to XAML elements
Correct Answer:
A
Chapter: 13
Q308:
How does a markup extension differ from a type converter in XAML?
A. Markup extensions are invoked with explicit syntax and can be used in property element syntax
B. Type converters are used for converting string values to types
C. Markup extensions are used only in XML namespaces
D. Type converters provide built-in conversions only
Correct Answer:
A
Chapter: 13
Q309:
What is the result of using the XAML <ListBox><ListBoxItem Content="Item 1"/><ListBoxItem Content="Item 2"/></ListBox>?
A. A ListBox with two items: "Item 1" and "Item 2"
B. A ListBox with a single item: "Item 1"
C. A ListBox with two items added programmatically in C#
D. A ListBox with one item containing two strings
Correct Answer:
A
Chapter: 13
Q310:
What does the XAML <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"><Color x:Key="1" A="255" R="255" G="255" B="255"/><Color x:Key="2" A="0" R="0" G="0" B="0"/></ResourceDictionary> define?
A. A dictionary of color resources with specified keys and values
B. A collection of items in a ListBox
C. A dictionary of font resources with specified keys and values
D. A set of style definitions for XAML elements
Correct Answer:
A
Chapter: 13
Q311:
What is the equivalent C# code for creating a button with a content property of a Rectangle object?
A. System.Windows.Controls.Button b = new System.Windows.Controls.Button(); System.Windows.Shapes.Rectangle r = new System.Windows.Shapes.Rectangle(); r.Width = 40; r.Height = 40; r.Fill = System.Windows.Media.Brushes.Black; b.Content = r;
B. System.Windows.Controls.Button b = new System.Windows.Controls.Button(); b.Content = new System.Windows.Shapes.Rectangle();
C. System.Windows.Controls.Button b = new System.Windows.Controls.Button(); System.Windows.Shapes.Rectangle r = new System.Windows.Shapes.Rectangle(); b.Content = r;
D. System.Windows.Controls.Button b = new System.Windows.Controls.Button(); b.Content = new System.Windows.Shapes.Rectangle();
Correct Answer:
A
Chapter: 13
Q312:
What is a property element in XAML?
A. An element used to set properties of other XAML elements
B. An element that represents an XML namespace
C. An element used to define a class in XAML
D. An element used to create an instance of a .NET object
Correct Answer:
A
Chapter: 14
Q313:
What is the equivalent C# code for the XAML <SolidColorBrush>White</SolidColorBrush>?
A. SolidColorBrush brush = new SolidColorBrush(Colors.White);
B. SolidColorBrush brush = new SolidColorBrush(); brush.Color = Colors.White;
C. SolidColorBrush brush = new SolidColorBrush(); brush.SetColor("White");
D. SolidColorBrush brush = (SolidColorBrush)TypeConverter.ConvertFrom("White");
Correct Answer:
A
Chapter: 14
Q314:
How does XAML handle the conversion of the string "White" in <Brush>White</Brush>?
A. It uses a type converter to convert the string to a SolidColorBrush.
B. It directly maps the string to the Brush class.
C. It throws an error because Brush is abstract.
D. It uses a built-in color converter that understands string values.
Correct Answer:
A
Chapter: 14
Q315:
How are child elements added to an IList in XAML?
A. By calling IList.Add for each child element.
B. By setting the Items property of the parent element.
C. By adding them as attributes of the parent element.
D. By directly appending them to the parent element.
Correct Answer:
A
Chapter: 14
Q316:
What is the function of x:Key in XAML when used in a dictionary?
A. It specifies a unique key for each item in a resource dictionary.
B. It defines the type of the dictionary items.
C. It determines the order of items in the dictionary.
D. It maps the key to the XML namespace.
Correct Answer:
A
Chapter: 14
Q317:
In XAML, how is a Hashtable represented?
A. Using the Collections namespace and specifying key-value pairs with x:Key.
B. By defining the Hashtable as an object and adding items programmatically.
C. Using the System.Collections namespace with the Hashtable class and adding items through attributes.
D. By converting the Hashtable to a list of key-value pairs.
Correct Answer:
A
Chapter: 14
Q318:
What does the XAML <Button x:Name="okbutton">OK</Button> specify?
A. It names the button "okbutton" so it can be accessed programmatically.
B. It sets the button's content to "OK".
C. It adds an event handler for the button's click event.
D. It specifies the button's width and height.
Correct Answer:
A
Chapter: 14
Q319:
What is the role of the InitializeComponent method in a XAML code-behind file?
A. It loads and initializes XAML-defined content into the window.
B. It sets up event handlers for the window.
C. It compiles the XAML into a binary format.
D. It adds custom functionality to the window.
Correct Answer:
A
Chapter: 14
Q320:
How does XAML handle plain text content for an element?
A. It uses a type converter to transform plain text into the parent element type if no properties are set.
B. It ignores plain text content if the element has properties.
C. It directly assigns the plain text as the value of the element's content property.
D. It raises an error if plain text is used as content.
Correct Answer:
A