Andrew Latham
Andrew Latham

Reputation: 6132

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?

Upvotes: 0

Views: 1068

Answers (1)

Lukasz Madon
Lukasz Madon

Reputation: 14994

Look at the msdn documentation. VerticalAlignment is an enum.

foo.VerticalAlignment = VerticalAlignment.Top;

Upvotes: 2

Related Questions