I want to update my interface, but it did not update even when the event was fired PropertyChanged. When I start, I get the first values, but after the changes, it will not be updated.
During debugging, I see that the values receiving the update and the event PropertyChangedwere fired, but the receiver did not receive the call.
(BTW: I'm relatively new to C #, respectively, in the concept of MV-VM.)
Xaml
<Page.DataContext>
<vm:MainPageViewModel x:Name="ViewModel" />
</Page.DataContext>
...
<TextBlock x:Name="LatitudeVar" Text="{Binding LatitudeVar, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="79" Canvas.Left="189" Canvas.Top="38" />
C # (MainPageViewModel)
public class MainPageViewModel : ViewModelBase, INotifyPropertyChanged
{
private Session _session;
public MainPageViewModel()
{
_session = Session.Instance;
}
public static readonly MainPageViewModel Instance = new MainPageViewModel();
public override async Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary<string, object> suspensionState)
{
Session.InitializeClient();
await StartGpsDataService();
await Task.CompletedTask;
}
...
private string _latitude;
public string LatitudeVar
{
get { return _session.Latitude; }
set { _session.Latitude = value; NotifyPropertyChanged(); }
}
...
public async Task StartGpsDataService()
{
await Session.InitializeDataUpdate();
}
public new event PropertyChangedEventHandler PropertyChanged;
[Annotations.NotifyPropertyChangedInvocator]
protected virtual void NotifyPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
C # (session)
public class Session : INotifyPropertyChanged
{
public static void InitializeClient()
{
MainPageViewModel mpvm = new MainPageViewModel();
_mpvm = MainPageViewModel.Instance;
}
private static Session _instance;
public static Session Instance
{
get
{
if (_instance == null)
{
_instance = new Session();
}
return _instance;
}
}
private static Session _sc;
internal static Session Sc
{
get { return _sc; }
set { _sc = value; }
}
private static MainPageViewModel _mpvm;
private string _latitude;
public string Latitude
{
get { return _latitude; }
set
{
if (_latitude == value) return; _latitude = value; RaiseOnPropertyChanged("Latitude"); }
}
...
public void UpdateGpsData(Geopoint point, Geopoint geopointOld)
{
_mpvm.LatitudeVar = point.Position.Latitude.ToString();
}
public static async Task InitializeDataUpdate()
{
Sc = Session.Instance;
Sc.StartTime = DateTime.Now;
Sc.GetPosition(Geoposition.Coordinate.Point);
}
public new event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void RaiseOnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
Some ways I tried before:
C # (MainPageViewModel)
private string _latitude;
public string LatitudeVar
{
get { return _latitude; }
set { _latitude = value; NotifyPropertyChanged("LatitudeVar"); }
}
Result . Values were not displayed.
C # (session)
public void UpdateGpsData(Geopoint point, Geopoint geopointOld)
{
Latitude = point.Position.Latitude.ToString();
}
Result . The values were filled at startup, but not updated.
EDIT: :
, ;) Session.cs - . relavant ViewModel. , :
public MainPageViewModel()
{
_session = Session.Instance;
_instance = this;
}