开发者

Silverlight Windows Phone 7: How to add content to a PivotControl?

I have a pivot control:

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

How can I a开发者_StackOverflow社区dd 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?


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...


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...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜