TextBox x = new TextBox();
x.Height = 30;
x.Width = 200;
x.Name = "Title";
x.Text = item.Title;
x.TextWrapping = TextWrapping.Wrap;
x.FontSize = 60;
StackPanel s = new StackPanel();
s.Children.Add(x);
I have placed this code inside a function called private async void Getnotes(); and im calling this function from the constructor after this.InitializeComponent();
But when i run the app, text boxes are not getting added . what could be the problem?
You need to add the stackpanel
to the window
window.AddChild(s);
You need to pass the window
to your function.
by default wpf app has a non named grid. name it "MyMainGrid".
and then you can add ether your stack panel.
MyMainGrid.Children.Add(s);
or directly add textbox to grid.
MyMainGrid.Children.Add(X);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.