I have the following two models in my app:
public class AppSettings : INotifyPropertyChanged
{
private Units _mainUnits; // Units is an Enum.
public Units MainUnits {
get { return _mainUnits; }
set {
if (!_mainUnits != value) {
_mainUnits = value;
this.OnPropertyChanged("MainUnits");
}
}
}
// Standard PropetyChanged event, etc. elided (using NotifyPropertyWeaver).
[...]
}
public class Ride : INotifyPropertyChanged
{
private double _rideDistance;
public double RideDistance {
get { return _rideDistance; }
set {
if (!_rideDistance != value) {
_rideDistance = value;
this.OnPropertyChanged("RideDistance");
}
}
}
// Standard PropetyChanged event, etc. elided (using NotifyPropertyWeaver).
[...]
}
Then on my application page I have a TextBlock
bound to the RideDistance property that uses an IValueConverter
that converts the RideDistance
from metres to either km or miles depending on the value of the MainUnits
enum.
This works fine as the values for the Ride
model change, however I want to refresh the page when the user changes the AppSettings.MainUnit property on the settings page and navigates "back" to the display page.
For example:
- App starts, page loads,
AppSettings.MainUnits
== Units.Imperial,RideDistance
shows as "1.3 miles". - User navigates to Settings page, and changes
AppSettings.MainUntis
to Units.Metric. - User presses "Back" to go back to first page.
- Page should now list
RideDistance
as2.1km
, however it still lists it in miles.
Restarting the app results in the desired behaviour as does explicitly navigating to the first page, but using the back button doesn't.
How can I force a refresh of the bound properties when the user uses the back button?
There's a small working app demonstrating this on the "RefreshProperties" branch of my FodyTest project:
Click the settings icon to change the units, navigate back to the start page, notice no difference, then refresh the page using the refresh button...