如何在没有MvvM Light ViewModel导航的情况下刷新页面

时间:2012-02-22 15:45:16

标签: silverlight windows-phone-7 silverlight-4.0 mvvm-light

在显示初始视图后,如何在没有页面导航的情况下更新viewmodel(Mvvm Light)中的嵌套ListBox。目前我正在使用更改的查询字符串进行重新进入的页面导航 - 必须有更好的方法吗?

RaisePropertyChanged没有任何效果,但是当通过OpenCallingPoints触发的soap请求的回调被触发时,我可以看到数据填充了正确的数据。

我尝试使用soap数据填充的网格是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>

1 个答案:

答案 0 :(得分:0)

你可能会看到这个: http://matthamilton.net/madprops-mvvmlight-screenconductor

我打算建议你看看Caliburn Micro并且正在四处寻找Mvvm-Light是否有类似的东西。那篇文章谈到了这一点。

这是我非常喜欢CM的事情之一,当您从Screen继承ViewModel时,您可以自动获取OnInitialize,OnActivate,OnDeactive,OnViewLoaded和OnViewReady方法。所以在这种情况下,你会在OnActivate中坚持这种逻辑。

在Windows Phone上,CM还会自动解析查询字符串参数,并用它们填充VM上的属性。

屏幕导体看起来像mvvm-light一样。