Answer the question
In order to leave comments, you need to log in
How to create a new TextBlock object in C# XAML?
Good evening.
Tell me how you can create a new TextBlock to display information in C # code?
I do this, I get an error:
public MainPage()
{
TextBlock story = new TextBlock();
story.Text = "asdas";
body.Children.Add(story);
this.InitializeComponent();
}
public MainPage()
{
TextBlock story = new TextBlock();
story.Text = "asdas";
body.Children.Add(story);
this.InitializeComponent();
}
class TextBlock
{
public string Text;
}
Answer the question
In order to leave comments, you need to log in
What's the error?
In my opinion, after InitializeComponent () this should be done otherwise you will not have a body yet.
The second code is strange, did you even understand what you were doing in it? Why do you need a TextBlock class with one Text field and how were you going to push the object of this class into the window? UI elements are not so simple, and it is not the heir of UIElement, which the Add method wants.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question