2013-04-08 108 views
0

我有一個GridView綁定與完美的數據源。綁定FlipView與GridView

public void LoadXmlData(string dateOfRunAsString) 
{ 
    IEnumerable<RetrieveFromXml> processList = from process in xmlDocument.Descendants("Process") 
               where process.Parent.Parent.Attribute("Date").Value == dateOfRun 
               select new RetrieveFromXml(process.Attribute("Name").Value, Convert.ToDouble(process.Elements("ActiveTime").Sum(sec => (int)sec))); 
    NameGrid.ItemTemplateSelector = myTemplateSelector; 
    NameGrid.ItemsSource = processesList; 
} 

現在的問題是我需要結合GridView到flipView。

就像FlipView將顯示一個GridView的每一天。

for(int i = 0; i<10; i++) 
{ 
    flipview.list.add(processfromxml(date+i)); 
    //Consider processfromxml() is returning a Ienumerable List 
} 

這樣的FlipView將顯示在GridView的第一天,就點擊旁邊會顯示在GridView的第二天。

請幫助如何在XAML實現這一點,C#在Windows 8

這是我的基礎類來獲取數據。

public class RetrieveProcessFromXml 
{ 
    private string name; 
    private double activeTime; 

    public RetrieveFromXml(string nameFromXml,double activeTimeFromxml) 
    { 
     name = nameFromXml; 
     activeTime = activeTimeFromxml; 
    } 

    public string Name 
    { 
     get { return name; } 
     set { name = value; } 
    } 

    public double ActiveTime 
    { 
     get { return activeTime; } 
     set { activeTime = value; } 
    } 
enter code here 

} //End Class 

回答

1

你有循環這樣

for(int i = 0; i<10; i++) 
{ 
    flipview.list.add(processfromxml(date+i)); 
    //Consider processfromxml() is returning a Ienumerable List 
} 

所以,如果你想在FlipView添加項目,那麼你必須添加GridViewIEnumerable名單。您必須將ItemsSource分配給特定的GridView,然後將GridView添加到FlipView

在這裏,我給你簡單的例子

XAML

<Page.Resources> 
    <DataTemplate x:Name="MyTemplate"> 
     <Border Background="DarkGray" Width="100" Height="100"> 
      <TextBlock Text="{Binding}" 
         Foreground="White" 
         HorizontalAlignment="Center" 
         VerticalAlignment="Center" 
         FontSize="30"/> 
     </Border> 
    </DataTemplate> 
</Page.Resources> 

<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}"> 
    <FlipView x:Name="flipview" Height="500" Width="500"/> 
</Grid> 

C#

List<SolidColorBrush> colors; 
protected override void OnNavigatedTo(NavigationEventArgs e) 
{ 
    colors = new List<SolidColorBrush> 
    { 
     new SolidColorBrush(Windows.UI.Colors.Red), 
     new SolidColorBrush(Windows.UI.Colors.Gainsboro), 
     new SolidColorBrush(Windows.UI.Colors.BlanchedAlmond), 
     new SolidColorBrush(Windows.UI.Colors.Turquoise), 
     new SolidColorBrush(Windows.UI.Colors.Azure), 
     new SolidColorBrush(Windows.UI.Colors.Teal), 
     new SolidColorBrush(Windows.UI.Colors.Tan), 
     new SolidColorBrush(Windows.UI.Colors.PowderBlue), 
     new SolidColorBrush(Windows.UI.Colors.WhiteSmoke), 
     new SolidColorBrush(Windows.UI.Colors.SeaGreen) 
    }; 
    for (int i = 0; i < 10; i++) 
    { 
     flipview.Items.Add(AddNewGridview(i)); 
    } 
} 

int i = 1, j = 0; 
GridView AddNewGridview(int k) 
{ 
    var gv = new GridView(); 
    gv.Background = colors[k]; 
    gv.ItemTemplate = this.Resources["MyTemplate"] as DataTemplate; 
    List<int> IDs = new List<int>(); 
    while(i < 17 + j) 
    { 
     IDs.Add(i); 
     i++; 
    } 
    j = i - 1; 
    gv.ItemsSource = IDs; 
    return gv; 
}