Background text box on a Windows phone

I want to change the background color to TextBlock on a Windows phone. Now I only have a text block that does not have a space next to the frame. I have this effect by this code:

<StackPanel Orientation="Horizontal" Background="{Binding Color}"> <TextBlock Text="{Binding Name}" Margin="12,0,0,0"></TextBlock> </StackPanel> 
+4
source share
2 answers

TextBlock does not have a background property on its own. You must set the background to a grid or canvas or a border or rectangle to fill it.

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

Instead of a grid, you can make a rectangle or border.

+11
source

You can also change the background color in the getFocus event, for example

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

Source: https://habr.com/ru/post/1479050/


All Articles