PrepAway - Latest Free Exam Questions & Answers

Which code fragment should you use?

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?

PrepAway - Latest Free Exam Questions & Answers

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

B.
<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>

C.
<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>

D.
<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>

2 Comments on “Which code fragment should you use?

  1. F says:

    A and D are incorrect because the style has an x:Key attribute (so the style has to be set explicitly by the labels), but the labels don’t refer to that style.
    B is incorrect because the style has no x:Key attribute and the first label refers to a style with name ‘Blue’ (thus not finding that style)

    C will show both label 1 and 2 in blue due to an implicit style.




    0



    0

Leave a Reply