2010-10-25 4 views
1

J'ai la page:complexe Silverlight liant

<view:PhoneApplicationPageBase 
    x:Class="Exadel.CCHMobile.View.NewsView" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" 
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" 
    xmlns:view="clr-namespace:Exadel.CCHMobile.View" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    FontFamily="{StaticResource PhoneFontFamilyNormal}" 
    FontSize="{StaticResource PhoneFontSizeNormal}" 
    Foreground="{StaticResource PhoneForegroundBrush}" 
    SupportedOrientations="Portrait" Orientation="Portrait" 
    mc:Ignorable="d" Height="768" Width="480" 
    shell:SystemTray.IsVisible="True"> 

    <view:PhoneApplicationPageBase.DataContext> 
     <Binding Path="News" Source="{StaticResource Locator}" /> 
    </view:PhoneApplicationPageBase.DataContext> 

    <!--LayoutRoot is the root grid where all page content is placed--> 
    <Grid x:Name="LayoutRoot" Background="Transparent"> 

     <Grid.RowDefinitions> 
      <RowDefinition Height="Auto"/> 
      <RowDefinition Height="*"/> 
     </Grid.RowDefinitions> 

     <StackPanel Grid.Row="0"> 
      <TextBlock Text="{Binding Path=TrackerTitle}" Style="{StaticResource PhoneTextNormalStyle}"/> 
     </StackPanel> 

     <ListBox Grid.Row="1" ItemsSource="{Binding Path=News}" VerticalAlignment="Stretch"> 
      <DataTemplate> 
<TextBlock Grid.Row="0" Grid.Column="0" Text="{Binding Title}"/> 
      </DataTemplate> 
     </ListBox> 
    </Grid> 

</view:PhoneApplicationPageBase> 

Mon modèle a la propriété TrackerTitle, est lie ok. J'ai aussi une collection News dans le modèle. Je ne peux pas lier la propriété Title de l'entité News au TextBlock. Qu'est-ce qui ne va pas? Merci.

Répondre

2

Ici

<ListBox Grid.Row="1" ItemsSource="{Binding Path=News}" VerticalAlignment="Stretch"> 
    <DataTemplate> 
     <TextBlock Grid.Row="0" Grid.Column="0" Text="{Binding Title}"/> 
    </DataTemplate> 
</ListBox> 

Le DataTemplate est suspendu au milieu de l'air. Cela devrait être dans ItemTemplate.

Aussi, est votre collection ObservableCollection? ou s'abonne-t-il à la notification de changement de propriété?