我是Windows Phone 7.1开发新手。我在VB.NET工作。Windows Phone ListBox/ScrollView控件不会更新
我正在处理类似'How to: Create a Basic Local Database Application for Windows Phone'的应用程序。
我已经设法使用上面的示例编写添加和删除代码。
但更新代码...当我返回到显示所有数据的页面时,它不会使用新信息进行更新。信息是保存(提交),因为当我在单独的页面中查看记录详细信息时,它们就在那里。
其中显示所有数据的XAML页面的代码是这样的:
<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>
我已经写在编辑页面的更新代码:
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
的厂商ID是顺利通过betweend页。我查过了。
数据库更新,但我似乎无法获得更新ScrollView记录。我也尝试了一个ListView控件..相同的结果。
模型类实现INotifyPropertyChanged,INotifyPropertyChanging。 viewmodel类实现INotifyPropertyChanged。
如果您需要任何其他细节,请问我。谢谢您阅读此篇!
我已经解决了通过在更新后添加NotifyPropertyChanged(“AllVendors”)来刷新ObservableCollection。 – milo2011
更新在另一个页面中进行,然后返回列表页面,其中显示所有供应商。在这种情况下,你是否可以使用OnNavigatedTo或OnNavigatedFrom?按照示例, – milo2011
可能是OnNavigatedTo –