pivotItems中的DataTemplate wp7

时间:2012-10-25 08:15:02

标签: windows-phone-7 xaml windows-phone-7.1

我想在wp7:

中创建一个pivotpage
 <Grid x:Name="LayoutRoot" Background="Transparent">
    <!--Pivot Control-->
    <controls:Pivot Title="MY APPLICATION">
        <!--Pivot item one-->
        <controls:PivotItem Header="item1">
            <Grid/>
        </controls:PivotItem>

        <!--Pivot item two-->
        <controls:PivotItem Header="item2">
            <Grid/>
        </controls:PivotItem>
    </controls:Pivot>
</Grid>

我需要将pivoItems与我的List<Article>自动绑定,类别文章定义如下:

  public class Article
{
    private string _logoUrl;
    public string LogoUrl
    {
        get { return _logoUrl; }
        set { _logoUrl = value; }
    }
    private string _title;
    public string Title
    {
        get { return _title; }
        set { _title = value; }
    }
    private string _descrption;
    public string Descrption
    {
        get { return _descrption; }
        set { _descrption = value; }
    }
}

如何使用Datatemplate将每个PivotItem绑定到每个文章(我需要每个文章的标题将显示在PivotItem的标题中以及webbrowser中的描述,因为它是HTML)

祝你好运

1 个答案:

答案 0 :(得分:0)

首先,要为每篇文章创建PivotItem,只需使用ItemsSource属性:

<controls:Pivot Title="MY APPLICATION" ItemsSource="{Binding Path=TheListOfArticles}">

要更改标题,请覆盖HeaderTemplate

<controls:Pivot ItemsSource="{Binding Path=TheListOfArticles}" Title="MY APPLICATION">
    <controls:Pivot.HeaderTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Path=Title}" />
        </DataTemplate>
    </controls:Pivot.HeaderTemplate>
</controls:Pivot>

同样,覆盖ItemTemplate以定义每个PivotItem的显示方式:

<controls:Pivot.ItemTemplate>
    <DataTemplate>
        <!-- whatever -->
    </DataTemplate>
</controls:Pivot.ItemTemplate>
相关问题