我有一页:
<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。怎么了? 谢谢。
答案 0 :(得分: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吗?或者是否订阅了房产变更通知?