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>
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.
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With