0

I am trying to create pivot item dynamically,

here the code which i used

paginationPivot.Items.Clear();

            for (int i = 1; i <= pagecount; i++)
            {
                TextBlock textBlock = new TextBlock();
                textBlock.Foreground = new SolidColorBrush(Colors.Blue);
                textBlock.FontSize = 30;
                textBlock.Text = (i).ToString();

                Border border = new Border();

                PivotItem pivotItem = new PivotItem() { Name="item"+i.ToString(), Header=textBlock, Content=border,Margin= new Thickness(0,-70,0,0), FlowDirection=System.Windows.FlowDirection.RightToLeft};

                paginationPivot.Items.Add(pivotItem);
            }

here the error which i got

A first chance exception of type 'System.ArgumentException' occurred in Microsoft.Phone.ni.dll

Can anybody please help me to solve this issue.

Thank you.

but i got this error while while creating pivot item

noorul
  • 1

1 Answers1

1

You can't set directly "Header=textBlock", just using a string hold content that you want to show. E.g: Header="header 1". If you want to use more complex UI, let's use HeaderTemplate:

<controls:Pivot.HeaderTemplate>
    <DataTemplate>
        <StackPanel Background="#666666" Margin="0">
            <TextBlock FontSize="30" Foreground="Blue" Text="{Binding}"/>
        </StackPanel>
    </DataTemplate>
</controls:Pivot.HeaderTemplate>

And after that:

<controls:PivotItem Header="header 1">
</controls:PivotItem>
ngvntoan
  • 82
  • 1
  • 5