Krzysztof Madej
Krzysztof Madej

Reputation: 40879

Background textblock on windows phone

I want to change background color on TextBlock on Windows phone. Now I've only got a textblock colored without a space near frame. This effect I've got by this code:

<StackPanel Orientation="Horizontal" Background="{Binding Color}">
    <TextBlock Text="{Binding Name}" Margin="12,0,0,0"></TextBlock>
</StackPanel>

Upvotes: 4

Views: 6576

Answers (2)

Mani
Mani

Reputation: 1374

TextBlock doesn't have a background property on its own. You have to put up a background grid or canvas or border or rectangle to full fill it.

<Grid Width="300" Height="100" Background="Blue">
    <TextBlock Name="MyTextBlock" Text="Hello World!" Foreground="Black" />
</Grid>

Instead of grid you can make a rectangle or border.

Upvotes: 11

Ebscer
Ebscer

Reputation: 27

You can also change the background color on the getFocus event like

private void TextBox_GotFocus(object sender, RoutedEventArgs e)
{
    (sender as TextBox).Background = new SolidColorBrush(Colors.Red);
}

Upvotes: 1

Related Questions