Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically create Pivot item and add stack panel dynamically? [closed]

I have a Pivot control in my Windows Phone 7 application, and would like to dynamically add PivotItems that contain additional controls laid out in a StackPanel. How can I do that programmtically?

I tried to add to PivotItem's children, but children doesn't exist in my PivotItem.

void ws_getMenuCompleted(object sender, getMenuCompletedEventArgs e)
{
    PivotItem pvt;
    for (int i = 0; i < e.Result.menu.Length; i++)
    {
        pvt = new PivotItem();
        pvt.Header = e.Result.menu[i].name.ToLower();

        StackPanel panel = new StackPanel(); 
        // ... UI creation in StackPanel removed...

        pvt.Children = panel; // << This doesn't work.

        pvtRestaurante.Items.Add(pvt);
        pvt = null;
    }
}
like image 731
user1885571 Avatar asked Oct 27 '25 10:10

user1885571


1 Answers

As PivotItem derives from ContentControl you should assign content property of the PivotItem. More info here http://msdn.microsoft.com/en-US/library/windowsphone/develop/microsoft.phone.controls.pivotitem%28v=vs.105%29.aspx

void ws_getMenuCompleted(object sender, getMenuCompletedEventArgs e)
        {
            PivotItem pvt;
            for (int i = 0; i < e.Result.menu.Length; i++)
            {
                pvt = new PivotItem();
                pvt.Header = e.Result.menu[i].name.ToLower();
                var stack = new StackPanel();
                pvt.Content = stack;
                pvtRestaurante.Items.Add(pvt);
                pvt = null;
            }
}
like image 186
Oleg Avatar answered Oct 29 '25 01:10

Oleg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!