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?

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?

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>



Leave a Reply 2

Your email address will not be published. Required fields are marked *


cybergabry

cybergabry

C ? Why? In my opinion it could be D.

F

F

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.