我想在Windows手机上更改TextBlock的背景颜色。现在我只有一个没有边框附近空间的彩色文本块。我通过以下代码获得了这种效果:
<StackPanel Orientation="Horizontal" Background="{Binding Color}">
<TextBlock Text="{Binding Name}" Margin="12,0,0,0"></TextBlock>
</StackPanel>
我想在Windows手机上更改TextBlock的背景颜色。现在我只有一个没有边框附近空间的彩色文本块。我通过以下代码获得了这种效果:
<StackPanel Orientation="Horizontal" Background="{Binding Color}">
<TextBlock Text="{Binding Name}" Margin="12,0,0,0"></TextBlock>
</StackPanel>
TextBlock本身没有背景属性。您需要添加一个背景网格、画布、边框或矩形来填充它。
<Grid Width="300" Height="100" Background="Blue">
<TextBlock Name="MyTextBlock" Text="Hello World!" Foreground="Black" />
</Grid>
你可以用矩形或边框替代网格。
private void TextBox_GotFocus(object sender, RoutedEventArgs e)
{
(sender as TextBox).Background = new SolidColorBrush(Colors.Red);
}