dotnet / dotnet/wpf

Is it possible to manipulate DP value inheritance parents of Content descendants?

Open
#511 1 comment 3 reactions 0 assignees View on GitHub
Question
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

Take a simple demo first. Create a ContentControl named "Example" and apply the following style:
```xaml

<Setter Property="Foreground" Value="Black" />

<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:Example">
<ContentPresenter TextElement.Foreground="Red" />
</ControlTemplate>
</Setter.Value>
</Setter>

```
And then, add the following code to the view:
```xaml

```

Run the program, and you'll see **a big BLACK text**, NOT RED.

I debugged the program and stepped into the place where DependencyProperty.GetValue works. Finally I found that the InheritanceParent property of that TextBlock is its logical parent "Example" not its visual parent.

It would be a problem to some controls with multiple contents like the following example:
![19040601](https://user-images.githubusercontent.com/4654507/55669006-9ccbe600-58a4-11e9-8ec5-49eab1820f60.png)
I have to solve this problem by wrapping a border with a foreground set to every content element. How dull!

At the end. What I expect is that I can manipulate the descendants of ContentPresenter to make them inherit DP value from their visual ancestors.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.