How to refresh page and content in a Windows8 application

So, I have an application for Windows 8 in which I install some data in defaultViewModel. My question is: after creating the page and I add something to the data, how do I refresh the page and display the changes made?

protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState) { //inital load var DataGroups = SampleDataSource.GetGroups((String)navigationParameter); this.DefaultViewModel["Items"] = DataGroups; } protected override void OnNavigatedTo(NavigationEventArgs e) { //when the page is navigated back to after making changes to sampledatasource base.OnNavigatedTo(e); this.DefaultViewModel.Clear(); var DataGroups = SampleDataSource.GetGroups("AllGroups"); this.DefaultViewModel["Items"] = DataGroups; } 

The changes I make are not reflected until the next time I open the application and the page reloads. Here is a view model:

  protected IObservableMap<String, Object> DefaultViewModel { get { return this.GetValue(DefaultViewModelProperty) as IObservableMap<String, Object>; } set { this.SetValue(DefaultViewModelProperty, value); } } 

This is the list I would like to update:

 <ListView x:Name="itemListView" AutomationProperties.AutomationId="ItemsListView" AutomationProperties.Name="Items" TabIndex="1" Grid.Row="1" Visibility="Collapsed" Margin="0,-10,0,0" Padding="10,0,0,60" ItemsSource="{Binding Source={StaticResource itemsViewSource}}" ItemTemplate="{StaticResource Standard80ItemTemplate}" SelectionMode="None" IsSwipeEnabled="false" IsItemClickEnabled="True" ItemClick="ItemView_ItemClick"/> 

Related to this:

 <CollectionViewSource x:Name="itemsViewSource" Source="{Binding Items}" d:Source="{Binding AllGroups[0].Items, Source={d:DesignInstance Type=data:SampleDataSource, IsDesignTimeCreatable=True}}"/> 

Msdn function:

 public void NotifyPropertyChanged(string propertyName) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } 
+4
source share
2 answers

Look at the code for the BindableBase class, which is usually created as in the shared folder of your Windows 8 Store project if you use templates (except for the Blank App template). If your starting point is the Blank App template, you can create a new BasicPage, and Visual Studio will ask if you want to include shared files.

Basically, the idea looks like this:

  • You are implementing the INotifyPropertyChanged interface
  • Create your own PropertyChanged event
  • The moment you set a new value for a property, you call this.OnPropertyChanged (propertyName), which throws a change event for this property. Then the control will be notified that the property has changed and will be automatically updated with the new value.
+3
source

Here is my approach:

 public bool Reload() { if (!this.Frame.BackStack.Any()) return false; var current = this.Frame.BackStack.First(); this.Frame.BackStack.Remove(current); return this.Frame.Navigate(current.SourcePageType, current.Parameter); } 

Good luck

+1
source

Source: https://habr.com/ru/post/1438111/


All Articles