I have a project based on the UNO template for VS2017.
I need to create standard controls in code behind, like TextBlock, Grids, TextBox, etc...
I use the MainPage.xaml.cs in the uno.shared project.
The following code fails with the error CS1061: (Translated from Spanish) "_TextBlock does not contain a definition for "Background "or any "Background extension method is accessible to accept a first argument of type "TextBlock"(some missing using directive or an assembly reference?)_"
var control = new TextBlock();
control.Foreground = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0));
control.Background = new SolidColorBrush(Color.FromArgb(255, 0, 255, 0));
control.Text = "Hello";
viewPort.Children.Add(control);
If I change TextBlock for another type of control like "TextBox", it works:
var control = new TextBox();
control.Foreground = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0));
control.Background = new SolidColorBrush(Color.FromArgb(255, 0, 255, 0));
control.Text = "Hello";
viewPort.Children.Add(control);
Thanks for the good work with the uno platform!
The Background property doesn't exists in UWP's TextBlock.
To achieve the same behavior, you need to surround it with a Border
You are right, in UWP not exits, it's my mistake due to the existence in Android!
Most helpful comment
The Background property doesn't exists in UWP's
TextBlock.To achieve the same behavior, you need to surround it with a
Border