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;
}
}
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;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With