[英]Items Data Binded to LongListSelector/Listbox not showing in windows phone 8 local database
[英]Reload LongListSelector with updated data from local database - Windows Phone 8
我的Windows Phone 8應用程序中的longlistselector出現問題。 從longlistselector中選擇並編輯一條記錄並將更改提交到我的本地數據庫后,除非關閉並重新打開該應用程序,否則longlistselector不會顯示更新的名稱。 數據肯定正在更新,只是沒有顯示。 有沒有辦法在應用仍處於打開狀態時選擇列表? 這是列表的Xaml:
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<phone:LongListSelector x:Name="llsModules"
Margin="0,0,-12,0"
ItemsSource="{Binding Modules}"
SelectionChanged="llsModules_SelectionChanged">
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,0,0,17">
<StackPanel Orientation="Horizontal">
<Grid HorizontalAlignment="Stretch" Width="420" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="100"/>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Name,StringFormat='Name: {0}'}"
TextWrapping="Wrap"
MaxWidth="300"
Style="{StaticResource PhoneTextLargeStyle}"
HorizontalAlignment="Left"
Grid.Row="1"
/>
</Grid>
</StackPanel>
這就是背后的代碼。
public ModulePage()
{
InitializeComponent();
DataContext = App.ViewModel;
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
App.ViewModel.LoadModulesData();
llsModules.ItemsSource = App.ViewModel.Module;
}
private void llsModules_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (llsModules.SelectedItem == null)
return;
NavigationService.Navigate(new Uri("/ModuleDetails.xaml?moduleid=" + (llsModules.SelectedItem as Modules).Id, UriKind.Relative));
}
這就是數據模型
[Table(Name = "Modules")]
public class Modules : INotifyPropertyChanged, INotifyPropertyChanging
{
public Modules()
{
}
private int _id;
[Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)]
public int Id
{
get
{
return _id;
}
set
{
if (_id != value)
{
NotifyPropertyChanging("Id");
_id = value;
NotifyPropertyChanged("Id");
}
}
}
private string _name;
[Column(DbType = "nvarchar(255)", CanBeNull = false)]
public string Name
{
get
{
return _name;
}
set
{
if (value == "")
throw new Exception("Module Name is a required field");
if (_name != value)
{
NotifyPropertyChanging("Name");
_name = value;
NotifyPropertyChanged("Name");
}
}
}
非常感謝!
在Xaml中,將用於顯示名稱的綁定更改為TwoWay
。
Text="{Binding Name, Mode=TwoWay, StringFormat='Name: {0}'}"
這使xaml知道監視Name
屬性的InotifyPropertyChanges。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.