2012-10-25 50 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>