【发布时间】:2012-02-22 15:45:15
【问题描述】:
在显示初始视图后,如何在没有页面导航的情况下更新我的视图模型 (Mvvm Light) 中的嵌套列表框。目前我正在使用不断变化的查询字符串进行可重入页面导航 - 一定有更好的方法吗?
RaisePropertyChanged 没有任何效果,尽管当通过 OpenCallingPoints 触发的肥皂请求的回调已触发时,我可以看到数据填充了正确的数据。
我试图用肥皂数据填充的网格是 CallingPointsGrid
短版代码...
<ListBox x:Name="ResultsListBox" Margin="0" VerticalAlignment="Top" ItemsSource="{Binding JourneyLegs, Mode=TwoWay}" Background="{StaticResource BackgroundWhiteGradientBrush}" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel x:Name="StationItem" Orientation="Vertical" VerticalAlignment="Top" background="{Binding id, Converter={StaticResource myconverter}}">
<Grid Name="CallingPointsGrid" Margin="15,10,55,10" Visibility="{Binding JourneyCallingPoints, Converter={StaticResource CallingPointsVisibilityConverter}}" Background="{StaticResource BackgroundWhiteGradientBrush}">
<ListBox Grid.Row="1" Name="CallingPointsListBox" DataContext="{Binding}" VerticalAlignment="Top" ItemsSource="{Binding JourneyCallingPoints, Mode=TwoWay}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel VerticalAlignment="Top" Orientation="Horizontal">
<TextBlock Margin="0" VerticalAlignment="Center" HorizontalAlignment="Left" Width="210" x:Name="Destination" Foreground="Black" Text="{Binding stationName}" />
<TextBlock Margin="5,0,5,0" VerticalAlignment="Center" HorizontalAlignment="Left" Width="75" x:Name="ScheduledDepartureTime" FontWeight="Bold" Foreground="{StaticResource BackgroundBlueLightSolidColor}" Text="{Binding timetable.scheduledTimes.arrival, StringFormat=\{0:HH:mm\}}" />
<TextBlock Margin="5,0,5,0" VerticalAlignment="Center" HorizontalAlignment="Left" Width="75" x:Name="ScheduledArrivalTime" FontWeight="Bold" Foreground="{StaticResource BackgroundBlueLightSolidColor}" Text="{Binding timetable.scheduledTimes.departure, StringFormat=\{0:HH:mm\}}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
<i:Interaction.Triggers>
<i:EventTrigger SourceName="ResultsListBox" EventName="Tap">
<i:EventTrigger.Actions>
<local:OpenCallingPoints />
</i:EventTrigger.Actions>
</i:EventTrigger>
</i:Interaction.Triggers>
【问题讨论】:
-
你使用
ObservableCollection作为你的物品来源吗? -
搭载 Ku6opr:您应该为列表使用 ObservableCollection,并确保您的底层对象(在列表中)实现 INotifyPropertyChanged。
-
嗨,据我了解,ListBox 在 WP7 上使用 ObservableCollection,但以防万一我弄错了。它没有任何影响,但在阴霾中我准备再试一次
-
您好,JourneyCallingPoints 只是一个普通的 get,在我的模型中定义的集合,在初始视图显示后填充(以支持多个 Soap 调用)。 JourneyLegs 在我的 ViewModel 中有一个 RaisePropertyChanged(实现 INotifyPropertyChanged 的 Mvvm Light)。 JourneyLegs 是 List
类型,JourneyLeg 类包含 JourneyallingPoints 类型,而这又是 List 。你是说我必须在基础类中的任何相关属性上定义一个 NotifyPropertyChange,尽管这些类型不是在 ViewModel 中定义而是在模型中定义??? -
项目源上是 ObservableCollection
标签: silverlight windows-phone-7 silverlight-4.0 mvvm-light