0

I'm new to Windows Phone 7.1 development. I work in VB.NET.

I'm working on an application similar with 'How to: Create a Basic Local Database Application for Windows Phone'.

I've managed to write the add and delete code using the sample above.

But the update code... when I return to the page where all the data is displayed, it won't update with the new informations. The information is save (submitted), because when I view the records details in a separate page, they are there.

The XAML page code where all the data is displayed is this:

<ScrollViewer  Margin="12,148,12,90" Name="scrollViewerVendors">
        <ItemsControl ItemsSource="{Binding AllVendors}">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Border BorderThickness="1" CornerRadius="12" Margin="2">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*" />
                                <RowDefinition Height="*" />
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <StackPanel Grid.Row="0" Grid.Column="0" Orientation="Horizontal" VerticalAlignment="Center">
                                <TextBlock Text="{Binding Name}" FontSize="28" />
                            </StackPanel>
                            <StackPanel Grid.Row="1" Grid.Column="0" Orientation="Horizontal" VerticalAlignment="Center">
                                <TextBlock Text="{Binding Address}" />
                            </StackPanel>
                            <Button Grid.Row="0" Grid.Column="1" Grid.RowSpan="2" 
                                x:Name="EditVendorButton" 
                                BorderThickness="1" 
                                Click="EditVendorButton_Click">
                                <Image Source="/Images/AppBar/appbar.edit.rest.png" />
                            </Button>
                            <Button 
                                Grid.Row="0" Grid.Column="2" Grid.RowSpan="2" 
                                x:Name="DeleteVendorButton" 
                                BorderThickness="1" 
                                Click="DeleteVendorButton_Click">
                                <Image Source="/Images/AppBar/appbar.delete.rest.png"  />
                            </Button>
                        </Grid>
                    </Border>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </ScrollViewer>

The update code I've written in the Edit page:

Using DemoAppDB As New DemoAppContext.DemoAppContext("Data Source=isostore:/DemoApp.sdf")
            Dim CurrentVendor = From VendorDetails In DemoAppDB.Vendors Where VendorDetails.VendorID = CInt(sVendorID) Select VendorDetails

            For Each Vendor In CurrentVendor
                Vendor.Name = TextBox1.Text
                Vendor.Address = TextBox2.Text
                Vendor.ContactPerson = TextBox3.Text
                Vendor.Phone = TextBox4.Text
                Vendor.Email = TextBox5.Text
                Vendor.Notes = TextBox6.Text
            Next
            'Save changes to the database
            DemoAppDB.SubmitChanges()
        End Using

The VendorID is passed successfully betweend pages. I've checked.

The database updates, but I can't seem to get the ScrollView record to update. I've also tried with a ListView control.. same result.

The model class Implements INotifyPropertyChanged, INotifyPropertyChanging. The viewmodel class Implements INotifyPropertyChanged.

If you need any other details, please ask me. Thank you for reading this!

milo2011
  • 339
  • 1
  • 9
  • 25

1 Answers1

0

Having had a look at the tutorial I'd say you've missed off

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
// Define the query to gather all of the to-do items.
var toDoItemsInDB = from ToDoItem todo in toDoDB.ToDoItems
                    select todo;

// Execute the query and place the results into a collection.
ToDoItems = new ObservableCollection<ToDoItem>(toDoItemsInDB);

    // Call the base method.
    base.OnNavigatedTo(e);
}

where, for you, you'd be updating AllVendors.

What is happening here is that, after the app has navigated back to the main page it is reloading the ObservableCollection that holds the data.

Faster Solutions
  • 7,005
  • 3
  • 29
  • 45
  • I've solved refreshing the ObservableCollection by adding NotifyPropertyChanged("AllVendors") after the update. – milo2011 May 30 '12 at 11:01
  • The update takes place in another page, and then it goes back to the list page, where all the vendors are displayed. In this case, do you this I could use OnNavigatedTo or OnNavigatedFrom? – milo2011 May 30 '12 at 11:05
  • probably OnNavigatedTo, as per the example – Faster Solutions May 31 '12 at 08:26