views:

26

answers:

2

I have a pivot control:

            PivotItem sectionPivot = new PivotItem()
            {
                Header = sect.Name,
                Content = new StackPanel()
            };

How can I add content to it?

Edit: The reason I'm doing it programmatically is because I don't know how many pivots there will be or what they will contain until runtime. Is there some way to do that in XAML?

+3  A: 

If you're going to do it all programatically, just add stuff to the stack panel you just created.

        var panel = new StackPanel();
        panel.Children.Add(new TextBlock() { Text = "Hello" });

        PivotItem sectionPivot = new PivotItem()
        {
            Header = sect.Name,
            Content = panel;
        };

I typed all that without doing any checking, but hypothetically that should work...

John Gardner
This should work, but if I had a choice I'd try to write it in xaml first... just sayin'
Nate Bross
@nate very true. thats why i prefaced mine with "if you're going to do it programatically..." :)
John Gardner
+1  A: 

Another answer from me. The OP added info to the question that they don't know how many there could be, and if you could still do it in XAML.

Yes, you can.

The Pivot control has an ItemsSource property, and you could bind that to something in your class that is being populated dynamically.

<controls:Pivot Title="MY APPLICATION" ItemsSource="{Binding MyPivotItemsSource}" />

Each item in that source would end up as a pivotitem. You'd also have to set up templates and stuff, so its still a lot of work...

John Gardner