2013-05-09 34 views
0

這是我使用無法使用的DataContext將數據綁定到木衛四livetiles

<callisto:LiveTile x:Name="liveTile1" Grid.Row="1" Grid.Column="0" 
     ItemsSource="{Binding}" 
     BorderBrush="White" BorderThickness="1" 
     Margin="15" Background="#FFCAD83E"> 
       <callisto:LiveTile.ItemTemplate> 
        <DataTemplate> 
         <Grid> 
          <StackPanel> 
           <TextBlock Text="Temp" FontWeight="SemiBold" 
              FontSize="25" FontFamily="Segoe UI Semibold" 
              Margin="10,20,0,0"> 
           </TextBlock> 
           <StackPanel Orientation="Horizontal" Margin="0,20,0,0"> 
            <TextBlock Text="{Binding Name}" x:Name="CrudeStMainTankName" 
               FontWeight="Light" 
               FontSize="20" 
               FontFamily="Segoe UI Semilight" 
               Margin="0,0,0,0"> 
            </TextBlock> 
            <TextBlock Text="{Binding Value}" x:Name="CrudeStMainTankValue" 
               FontWeight="Light" 
               FontSize="20" 
               FontFamily="Segoe UI Semilight" 
               Margin="0,00,0,0"> 
            </TextBlock> 
           </StackPanel> 
          </StackPanel> 
         </Grid> 
        </DataTemplate> 
       </callisto:LiveTile.ItemTemplate> 
</callisto:LiveTile> 

的動態磁貼模板這是我如何分配我的DataContext這個活的瓷磚

liveTile1.DataContext = cds.ComponentCollection[0]; 

我試圖調試它,但我無處可去。

現在cds.ComponentCollection [0]從包含名稱,類型和值的集合中檢索項目,並從此集合項目中,我將Textblock屬性名稱綁定到項目屬性名稱和文本塊屬性值到項目屬性值。
任何人都可以請幫助我如何得到這個工作?

回答

1

LiveTileItemsControl因此您需要將其ItemsSource屬性設置爲集合。使用您的XAML,這意味着您需要設置DataContext以完成cds.ComponentCollection,不僅適用於其第一項,即:

liveTile1.DataContext = cds.ComponentCollection;