0
votes

How do I update a nested ListBox in my viewmodel (Mvvm Light) without page navigation after the initial view has been displayed. Currently I am doing a re-entrant page navigation using a changing querystring - there must be a better way?

RaisePropertyChanged is having no effect although I can see the data is populated with the correct data when the callback from the soap request triggered via OpenCallingPoints has fired.

The grid I am trying to populate with soap data is CallingPointsGrid

Short version of the code...

<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
Do you use ObservableCollection as your items source?Ku6opr
To piggyback onto Ku6opr: you should use an ObservableCollection for your lists, and make sure that your underlying objects (in the lists) implement INotifyPropertyChanged.Robaticus
Hi, as I understand it the ListBox uses ObservableCollection on WP7 but just in case I got it wrong. It did not have any affect but in the haze I am prepared to try it againJohn Parr
Hi again, JourneyCallingPoints is just a normal get, set defined in my model which is post populated after the initial view is shown (to svae multiple Soap calls). JourneyLegs has a RaisePropertyChanged in my ViewModel (Mvvm Light which implements INotifyPropertyChanged). JourneyLegs is ofType List<JourneyLeg> and the JourneyLeg class contains type JourneyallingPoints which in turn List<RealtimeCallingPoint>. Are you saying I must define a NotifyPropertyChange on any relevant property within the underlying classes though those types are not defined in the ViewModel but the model???John Parr
It was ObservableCollection on the items sourceJohn Parr

1 Answers

0
votes

You might look at this: http://matthamilton.net/madprops-mvvmlight-screenconductor

I was going to suggest you look at Caliburn Micro and was searching around to see if Mvvm-Light had something similar. That article talks about that.

That's one of the things I really like about CM, when you inherit your ViewModel from Screen you automatically get OnInitialize, OnActivate, OnDeactive, OnViewLoaded, and OnViewReady methods you can override. So in this case you'd stick that logic in OnActivate.

On windows phone CM will also auto parse out the query string parameters and populate a property on your VM with them.

It looks like the screen conductor allows you to do similar with mvvm-light.