Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Set Foreground of ContentControl's Content

$
0
0

I'd like to set the foreground color of the content of my ContentControl to a specific color. The code below shows my attempts to set the color for the text 'Test' but it stays black.

What am I missing?

Thanks,
Guido

<Window x:Class="Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300"><Grid><ContentControl Grid.Row="0"><ContentControl.Template><ControlTemplate TargetType="{x:Type ContentControl}"><ContentControl Foreground="Yellow" TextBlock.Foreground="Magenta" TextElement.Foreground="Cyan"><ContentPresenter Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" /></ContentControl></ControlTemplate></ContentControl.Template><ContentControl.ContentTemplate><DataTemplate><ContentControl Foreground="Red" TextBlock.Foreground="Green" TextElement.Foreground="Blue" Content="{Binding}" /></DataTemplate></ContentControl.ContentTemplate><!-- Content --><TextBlock>Test</TextBlock></ContentControl></Grid></Window>


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>