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 4577204
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:18:49+00:00 2026-05-21T20:18:49+00:00

Let say you have 2 WPF buttons. One uses TextBlock, not the other one.

  • 0

Let say you have 2 WPF buttons. One uses TextBlock, not the other one.

<Button x:Name="Button1">
    <TextBlock>inside textblock</TextBlock>
</Button>

and

<Button x:Name="Button2">
   no textblock
</Button>

Both buttons use this template which sets the “Foreground” dependency property to white:

<ControlTemplate x:Key="ButtonTemplate" TargetType="{x:Type Button}">            
   <Border Name="Border" TextElement.Foreground="White">
   <ContentPresenter/>
</ControlTemplate>

The button with TextBlock has black text. The other one works fine. Why?

  • 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-21T20:18:50+00:00Added an answer on May 21, 2026 at 8:18 pm

    This is a matter of value inheritance as H.B. points out. Property value inheritance generally follows the logical tree.

    In the first case:

    <Button x:Name="Button1">
        <TextBlock>inside textblock</TextBlock>
    </Button>
    

    The TextBlock’s logical parent is the Button, so it will inherit it’s value from Button and so on up the logical tree. So in the following code, the TextBlock will be red:

    <Button x:Name="Button1" TextBlock.Foreground="Red">
        <TextBlock>inside textblock</TextBlock>
    </Button>
    

    In the second case:

    <Button x:Name="Button2">
       no textblock
    </Button>
    

    A TextBlock is ultimately created by the ContentPresenter (see the ContentPresenter.ChooseTemplate method in ILSpy/Reflector). In this case, the TextBlock’s logical parent is the ContentPresenter. So it will inherit it’s value from ContentPresenter and so on up the logical tree, to the Border which has the White foreground defined.

    This is documented briefly here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let say I have are two WPF forms: Form1 and Form2 . Form1 contains
We have a WPF application, let’s say I have a Department object, in it
Let say i have some words AB, AAB, AA. AB is not a prefix
Let's say we show some WPF Window and comes moment when we have to
Standard WPF 4 Datagrid. Let' say I have datagrid 200 pixels wide, and 2
Let's say I have the following code in WPF application: try { // NorthwindDataContext
Let say I have a web page, index, and have a button can login,
I have a general question about data templates in WPF. Let's say I have
Let say I have abstract class called: Tenant and Customer. The tenant in this
Let say I have an array like: Array ( [0] => Array ( [Data]

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.