2010-10-25 35 views
1

我已經頁面:Silverlight的複合物結合

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

我的模型具有財產TrackerTitle,是結合確定。我也有一個新聞收集模型。我無法將News實體的Title屬性綁定到TextBlock。哪裏不對? 謝謝。

回答

2

這裏

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

的DataTemplate中是懸在半空。它應該在ItemTemplate中。

另外,您的收藏ObservableCollection?還是訂閱「物業變更通知」?