Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4071912
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:49:03+00:00 2026-05-20T16:49:03+00:00

I am preparing for an exam and studying questions. However I have one question

  • 0

I am preparing for an exam and studying questions. However I have one question which in my opinion the answer is wrong. Here’s the question where the correct answer is D:

You use Microsoft .NET Framework 4 to
create a Windows Presentation
Foundation (WPF) application. The
application has a window named
MainWindow that has a StackPanel
control named sp as the root element.
You want to create a Button control
that contains a TextBlock control with
the “Save” Text property. You need to
create the control dynamically and add
the control to sp. Which code segment
should you write in the constructor of
the MainWindow class

A:

Button btn = new Button();
TextBlock text = new TextBlock();
text.Text = "Save";
btn.Content = text;
sp.DataContext = btn;

B:

Button btn = new Button();
TextBlock text = new TextBlock();
text.Text = "Save";
btn.Content = text;
sp.Children.Add(btn);

C:

Button btn = new Button();
TextBlock text = new TextBlock();
text.Text = "Save";
sp.Children.Add(btn);
sp.Children.Add(text);

D:

Button btn = new Button();
TextBlock text = new TextBlock();
text.Text = "Save";
btn.ContentTemplateSelector.SelectTemplate(text, null);
sp.Children.Add(btn);

In my opinion the correct answer is B? Do you have any sugesstions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T16:49:03+00:00Added an answer on May 20, 2026 at 4:49 pm

    I think you’re right. Answer D makes no sense at all, because:

    1. you don’t need the ContentTemplateSelector, since you’re defining the content explicitly
    2. ContentTemplateSelector shouldn’t be used explicitly, it’s used by ContentControl when it needs to render non-visual content
    3. ContentTemplateSelector is null by default, so the code in answer D would crash with a NullReferenceException
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently preparing for an exam. One of the question I found in an
I'm preparing for an exam and after going over some sample exercises (which have
I am preparing for a SCJP exam and when studying widening part it's given
i'm preparing for an exam and I'm having a question that I hope someone
I'm preparing to the SQL Server exam (70-431). I have the book from Sybex
I am preparing to use continuous integration for the first time. I will be
I'm preparing to send mass email to customers which is in html + images.
I'm preparing the SCJP exam with the almost official study book ("SCJP Sun Certified
When I was preparing for TOGAF exam, I came across Open Standard available for
In preparing to a OOP exam, I enjoyed seeing g++ compile the following code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.