2012-10-25 27 views
1

我想创建在WP7一个pivotpage:的DataTemplate在pivotItems WP7

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

最好的问候

回答

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>