Skip to main content

Visual Programming MCQs with Answers

Practice important Visual Programming MCQs with answers and explanations.

Multiple Choice Questions

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();
View Answer
A

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
View Answer
A

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");
View Answer
A

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.
View Answer
A

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.
View Answer
A

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.
View Answer
A

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.
View Answer
A

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.
View Answer
A

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.
View Answer
A

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.
View Answer
A

Test Your Knowledge

Take a timed quiz on Visual Programming

🚀 Start Quiz Now