How to change textblock text?
How to change textblock text?
19 Aug 2022, 11:49
I am trying to change text of a textblock I created in OnStart()
protected override void OnStart()
{
var textblock = new TextBlock
{
Width = 100,
Height = 50,
Left = 200,
Top = 40,
Text = "",
Margin = "2 6 2 2",
BackgroundColor = Color.Black,
ForegroundColor = "#39ff14",
FontSize = 24
};
var canvas = new Canvas();
Chart.AddControl(canvas);
canvas.AddChild(textblock);
}
but cannot access "textblock.Text" to set its text to something else. I am trying to do the following...
protected override void OnTick()
{
textblock.Text = "Some new text"
}
How can I achieve something like this?
thanks
Replies
hishalv
19 Aug 2022, 12:28
RE:
PanagiotisCharalampous said:
Hi hishalv,
You need to move textblock outside OnStart and make is a class variable so that it is accessible by other members too.
Best Regards,
Panagiotis
Hi Panagiotis,
thanks for the quick reply, however when I tried this I get the error...
"the contexual keyword var may only appear within a local variable declaration or in a script code"
It works if the data type is a string, bool, etc....except a var.
Any thoughts?
@hishalv
PanagiotisCharalampous
19 Aug 2022, 12:46
Hi hishalv,
You need to use the actual type
TextBlock _textBlock
Best Regards,
Panagiotis
Join us on Telegram and Facebook
@PanagiotisCharalampous
PanagiotisCharalampous
19 Aug 2022, 11:56
Hi hishalv,
You need to move textblock outside OnStart and make is a class variable so that it is accessible by other members too.
Best Regards,
Panagiotis
Join us on Telegram and Facebook
@PanagiotisCharalampous