Matthias
Matthias

Reputation: 13424

Errors with Background Style on a TextBlock

I have following style in a xaml file:

<Style x:Key="LabelText"
             TargetType="TextBlock">
                <Setter Property="FontFamily" Value="Segoe Black"/>
                <Setter Property="FontSize" Value="14"/>
                <Setter Property="Foreground" Value="#FFB3B4C1"/>
                <Setter Property="TextAlignment" Value="Center"/>
                <Setter Property="VerticalAlignment" Value="Center"/>
                <Setter Property="Background" Value="#FF3B596E"/>
            </Style>

Unfortunately, the

<Setter Property="Background" Value="#FF3B596E"/>

isn't recognized by Visual Studio, so my xaml webpage won't load. If I remove the background setter it works, but I need this background.

Is there some sort of workaround to fix this issue?

Upvotes: 2

Views: 703

Answers (3)

bendewey
bendewey

Reputation: 40235

You can also use a ContentControl instead of a TextBlock, no need to wrap the visual then.

<ContentControl Content='MyText' Background="#FF3B596E" />

Upvotes: 0

Joel Martinez
Joel Martinez

Reputation: 47749

You could take a jQuery-like approach, and walk the visual tree when the page loads to wrap all textblocks with a border (with the appropriate style applied).

Upvotes: 0

Thomas Levesque
Thomas Levesque

Reputation: 292405

In Silverlight the TextBlock class doesn't have a Background property, its always transparent. If you want it to have a background color, put it in another control, like a Border, on which you set the background color.

Another option is to use a Label instead of a TextBlock.

Upvotes: 2

Related Questions