Question: You use Microsoft .NET Framework 4 to create a Windows Presentation Foundation (WPF) application. You want the application to contain a window as shown in the following exhibit. The application contains the following code fragment. (Line numbers are included for reference only.)
01<Grid ShowGridLines=”True”>
02<Grid.ColumnDefinitions>
03<ColumnDefinition />
04<ColumnDefinition />
05<ColumnDefinition />
06</Grid.ColumnDefinitions>
07<Grid.RowDefinitions>
08<RowDefinition />
09<RowDefinition />
10<RowDefinition />
11</Grid.RowDefinitions>
12
13<TextBlock FontWeight=”Bold” Grid.Row=”1″ Grid.Column=”0″>Quarter</TextBlock>
14<TextBlock FontWeight=”Bold” Grid.Row=”1″ Grid.Column=”1″>Quarter 1</TextBlock>
15<TextBlock FontWeight=”Bold” Grid.Row=”1″ Grid.Column=”2″>Quarter 2</TextBlock>
16<TextBlock FontWeight=”Bold” Grid.Row=”2″ Grid.Column=”0″>Products</TextBlock>
17<TextBlock Grid.Row=”2″ Grid.Column=”1″>100000</TextBlock>
18<TextBlock Grid.Row=”2″ Grid.Column=”2″>150000</TextBlock>
19</Grid>
You need to create the application window. Which code fragment should you insert at line 12?
<Rectangle Grid.ColumnSpan="3" Fill="#73B2F5"/> <Rectangle Grid.Row="1" Grid.RowSpan="2" Fill="#73B2F5"/> <TextBlock FontSize="20" FontWeight="Bold" Grid.Row="0">2010 Products Shipped</TextBlock>
<Rectangle Grid.ColumnSpan="3" Fill="#73B2F5"/> <Rectangle Grid.Row="1" Grid.RowSpan="1" Fill="#73B2F5"/> <TextBlock FontSize="20" FontWeight="Bold" Grid.ColumnSpan="3" Grid.Row="0">2010 Products Shipped</TextBlock>
<Rectangle Grid.ColumnSpan="3" Fill="#73B2F5"/> <Rectangle Grid.RowSpan="3" Fill="#73B2F5"/> <TextBlock FontSize="20" FontWeight="Bold" Grid.ColumnSpan="3" Grid.Row="0">20 Products Shipped</TextBlock>
<Rectangle Grid.Column="1" Grid.ColumnSpan="2" Fill="#73B2F5"/> <Rectangle Grid.RowSpan="3" Fill="#73B2F5"/> <TextBlock Grid.Column="1" FontSize="20" FontWeight="Bold" Grid.ColumnSpan="3" Grid.Row="0">2010 Products Shipped</TextBlock>
Correct Answer: 3
Question: You use Microsoft .NET Framework 4 to create a Windows Presentation Foundation (WPF) application. You plan to create a window that has a layout as shown in the following exhibit. You need to define the code fragment to create the window layout. Which code fragment should you use?
<StackPanel Orientation="Vertical" Background="Gainsboro">
<TextBlock Text="Name:" /> <TextBox VerticalAlignment="Top" />
<TextBlock Text="Password:" />
<TextBox VerticalAlignment="Top" />
<Button HorizontalAlignment="Center" VerticalAlignment="Center" Width="100" Content="Submit" />
</StackPanel><Grid Background="Gainsboro">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Text="Name:" Grid.Row="0"/>
<TextBox VerticalAlignment="Top" Grid.Row="0" />
<TextBlock Text="Password:" Grid.Row="1"/>
<TextBox VerticalAlignment="Top" Grid.Row="1" /> <Button HorizontalAlignment="Center" VerticalAlignment="Center" Width="100" Content="Submit" Grid.Row="2"/>
</Grid><UniformGrid Rows="3" Columns="1" Background="Gainsboro"> <TextBlock Text="Name:" />
<TextBox VerticalAlignment="Top" />
<TextBlock Text="Password:" />
<TextBox VerticalAlignment="Top" />
<Button HorizontalAlignment="Center" VerticalAlignment="Center" Width="100" Content="Submit" />
</UniformGrid><UniformGrid Rows="5" Background="Gainsboro">
<TextBlock Text="Name:" />
<TextBox VerticalAlignment="Top" />
<TextBlock Text="Password:" />
<TextBox VerticalAlignment="Top" />
<Button HorizontalAlignment="Center" VerticalAlignment="Center" Width="100" Content="Submit" />
</UniformGrid>
Correct Answer: 4
Question: You use Microsoft .NET Framework 4 to create a Windows Presentation Foundation (WPF) application. The application contains a window that has two labels named First and Second. You need to display the label named First in blue. Which code fragment should you use?
<Grid>
<Grid.Resources>
<Style x:Key="Blue" TargetType="{x:Type Label}">
<Setter Property="Label.Foreground" Value="Blue"/>
</Style>
</Grid.Resources>
<StackPanel Orientation="Vertical">
<Label Name="First">Text #1</Label>
<Label Name="Second">Text #2</Label>
</StackPanel> </Grid><Grid>
<Grid.Resources> <Style x:Uid="Blue">
<Setter Property="Label.Foreground" Value="Blue"/>
</Style>
</Grid.Resources>
<StackPanel Orientation="Vertical">
<Label Name="First" Style="{StaticResource Blue}">Text #1</Label> <Label Name="Second">
Text#2</Label> </StackPanel> </Grid><Grid>
<Grid.Resources>
<Style x:Uid="First" TargetType="{x:Type Label}"> <Setter Property="Foreground" Value="Blue"/>
</Style>
</Grid.Resources>
<StackPanel Orientation="Vertical">
<Label Name="First">Text #1</Label>
<Label Name="Second">Text #2</Label>
</StackPanel> </Grid><Grid>
<Grid.Resources> <Style x:Key="First" TargetType="{x:Type Label}"> <Setter Property="Foreground" Value="Blue"/>
</Style>
</Grid.Resources>
<StackPanel Orientation="Vertical">
<Label Name="First">Text #1</Label>
<Label Name="Second">Text #2</Label>
</StackPanel> </Grid>
Correct Answer: 3
Question: You use Microsoft .NET Framework 4 to create a Windows Presentation Foundation (WPF) application. You write the following code fragment.
<Style TargetType="{x:Type Label}">
<Setter Property="Foreground" Value="Blue"/>
</Style>
You need to ensure that the style is applied to all labels within the application. What should you do?
- Add the style to the <Grid.Resources> section of the main window.
- Add the style to the <Window.Resources> section of the main window.
- Add the style to the <Application.Resources> section of the App.xaml file.
- Add the style to the <Application.Properties> section of the App.xaml file.
- Add the style to the <ResourceDictionary> section of the ResourceDictionary.xaml file.
Correct Answer: 3
Question: You use Microsoft .NET Framework 4 to create a Windows Presentation Foundation (WPF) application. The application contains the following code fragment.
<StackPanel> <TextBlock Style="{StaticResource MyStyle}">Hello World</TextBlock>
<Button Style="{StaticResource MyStyle}">Ok</Button>
</StackPanel>
You need to define a style that applies the following properties to the text in the StackPanel object:
“FontSize = 32”
“FontWeight = Bold”
Which code fragment should you use?
<Style x:Key="MyStyle" TargetType="{x:Type Control}">
<Setter Property="TextElement.FontSize" Value="32" />
<Setter Property="TextElement.FontWeight" Value="Bold" />
</Style><Style x:Key="MyStyle" TargetType="{x:Type FrameworkElement}">
<Setter Property="TextElement.FontSize" Value="32" />
<Setter Property="TextElement.FontWeight" Value="Bold" />
</Style><Style x:Key="MyStyle" TargetType="{x:Type TextElement}"> <Setter Property="Control.FontSize" Value="32" />
<Setter Property="Control.FontWeight" Value="Bold" /> </Style><Style x:Key="MyStyle" TargetType="{x:Type UserControl}"> <Setter Property="Control.FontSize" Value="32" />
<Setter Property="Control.FontWeight" Value="Bold" /> </Style>
Correct Answer: 2