What should you do to perform the following tasks?

You are creating a Windows Presentation Foundation application by using Microsoft .NET Framework 3.5.
You need to perform the following tasks:
* Add a control to a window by using the following XAML code fragment.
<local:RedTextControl Background="Yellow" />
* Ensure that the background color of the control is yellow.
* Ensure that the foreground color is red

What should you do?

You are creating a Windows Presentation Foundation application by using Microsoft .NET Framework 3.5.
You need to perform the following tasks:
* Add a control to a window by using the following XAML code fragment.
<local:RedTextControl Background=”Yellow” />
* Ensure that the background color of the control is yellow.
* Ensure that the foreground color is red

What should you do?

A.
Add the following code segment to a code-behind file.
public class RedTextControl : ContentControl
{
public void RedTextControl()
{
TextBlock tb = new TextBlock();
tb.Foreground = Brushes.Red;
tb.Text = “Hello”;
this.AddChild(tb);
}
}

B.
Add the following code segment to a code-behind file.
public class RedTextControl : Control
{
public void RedTextControl()
{
TextBlock tb = new TextBlock() ;
tb.Foreground = Brushes.Red ;
tb.Text = “Hello” ;
this.AddLogicalChild(tb) ;
}
}

C.
Add the following XAML code fragment to an XAML file.
<UserControl x:Class=”RedTextControl” xmlns=”…” xmlns:x=”…”>
<DockPanel>
<TextBlock Foreground=”Red” Text=”Hello” />
</DockPanel>
</UserControl>
Add the following code segment to a code-behind file.
internal partial class RedTextControl
{
public void RedTextControl()
{
InitializeComponent();
Background.CoerceValue(TextBlock.BackgroundProperty);
}
}

D.
Add the following XAML code fragment to an XAML file.
<UserControl x:Class=”RedTextControl” xmlns=”…” xmlns:x=”…”>
<DockPanel>
<TextBlock Foreground=”Red” Text=”Hello” />
</DockPanel>
</UserControl>
Add the following code segment to a code-behind file.
internal partial class RedTextControl : UserControl
{
public void RedTextControl()
{
InitializeComponent();
}
}



Leave a Reply 0

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