简体   繁体   中英

WP7: Dynamically add items to a Grid

I am trying to add multiple items in to a grid, so that later items will pop up underneath earlier items.

            TextBox foo = new TextBox();
            foo.Text = " " + id + " ";
            foo.Width = 440;
            foo.Height = 200;
            foo.VerticalAlignment = "Top";
            foo.Background = new SolidColorBrush(Colors.Red);
            ((Grid)daysPanels[id].Content).Children.Add(foo);

Unfortunately, the VerticalAlignment = "Top" line isn't working, it says it can't implicitly convert type "String" to type "VerticalAlignment". Am I doing this the right way and how can I fix that error?

Look at the msdn documentation . VerticalAlignment is an enum.

foo.VerticalAlignment = VerticalAlignment.Top;

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM