RoundRunningView med nytt event "Loaded" triggas endast en gg när sidan är renderad

This commit is contained in:
2025-10-20 16:46:38 +02:00
parent 2797162a93
commit ecd3e90dbf
5 changed files with 13 additions and 48 deletions

View File

@ -31,7 +31,6 @@ public partial class InfoPopupViewModel : ObservableObject, IQueryAttributable
[RelayCommand]
private async Task Cancel()
{
//await _popupService.ClosePopupAsync(Shell.Current);
_popupEvent.RaiseInfoPopupClose(PopupId);
}

View File

@ -23,15 +23,12 @@ public partial class ParticipantViewModel : BaseViewModel
IMethodSharingService<Participant> sharingService,
IPopupService popupService,
IPopupEventHub popupEvent
//,
//InfoPopupViewModel infoPopupViewModel
) : base()
{
_Repository = repo;
_sharingService = sharingService;
_popupService = popupService;
_popupEvent = popupEvent;
//_infoPopupViewModel = infoPopupViewModel;
ParticipantObject = new Participant();
ParticipantList = new ObservableCollection<Participant>();
IsSaveCommandEnabled = true;
@ -55,13 +52,11 @@ public partial class ParticipantViewModel : BaseViewModel
#endregion
public bool PopupVisad { get; set; }
[ObservableProperty]
private bool isSaveCommandEnabled;
public bool PopupVisad { get; set; }
#region Get Method
public ObservableCollection<Participant> Get()
{
@ -131,25 +126,6 @@ public partial class ParticipantViewModel : BaseViewModel
}
//[RelayCommand(CanExecute = nameof(IsSaveCommandEnabled))]
//private async Task<bool> Save()
//{
// if (_Repository == null || ParticipantObject == null)
// {
// return false;
// }
// var tmpTask = _Repository.Save(ParticipantObject);
// int tmp = tmpTask.GetAwaiter().GetResult();
// if (tmp != -1)
// {
// ParticipantObject = new Participant();
// this.Get();
// await Shell.Current.GoToAsync("..");
// }
// return tmp != -1;
//}
[RelayCommand]
private void DeleteAsync(Participant pp)
{
@ -173,11 +149,6 @@ public partial class ParticipantViewModel : BaseViewModel
}, loadingMessage: "Laddar data...");
}
//private void ClosePopup()
//{
// _popupService.ClosePopupAsync(Shell.Current).GetAwaiter().GetResult();
//}
private async void infoPopupViewModel_ClosePopupRequested(object? sender, PopupCloseEventArgs e)
{
if (e.PopupId != _activePopupId)

View File

@ -51,9 +51,6 @@ public partial class RoundRunningViewModel : ObservableObject
private readonly IPopupService _popupService;
private readonly IPopupEventHub _popupEvent;
//private ObservableCollection<RoundBuilderGroup> _GameRoundList = new();
//private ObservableCollection<Participant> _ParticipantList = new();
[ObservableProperty]
private ObservableCollection<RoundBuilderElement> roundElements;
[ObservableProperty]
@ -72,11 +69,9 @@ public partial class RoundRunningViewModel : ObservableObject
}
public ObservableCollection<RoundBuilderElement> Get()
public void Get()
{
if (_objectMessage.CurrentGroup != null)
{
//CurrentGroup är satt från RoundStarting ViewModel
@ -109,7 +104,6 @@ public partial class RoundRunningViewModel : ObservableObject
}
TriggerRebuild();
}
return RoundElements;
}
[RelayCommand]
@ -248,8 +242,9 @@ public partial class RoundRunningViewModel : ObservableObject
if (player.PlayerPoints > 10000)
{
var winner = RoundElements.FirstOrDefault(e => e.ParticipantId == player.PlayerId);
var oldStatus = winner.Status;
winner.Status = GamePointStatus.Winning;
if (playerPointsOld < 10000)
if (playerPointsOld < 10000 && oldStatus != winner.Status)
{
Show_a_Popup(
player.PlayerName,
@ -265,7 +260,6 @@ public partial class RoundRunningViewModel : ObservableObject
}
}
}
//oldPart = element.ParticipantId;
if (!PlayerColumns.Contains(player))
{

View File

@ -203,18 +203,15 @@ public partial class RoundStartingViewModel : ObservableObject
}
[RelayCommand]
public async Task<bool> RoundSelected(RoundBuilderElement element)
public async Task RoundSelected(RoundBuilderElement element)
{
bool goneOk = false;
var rbGroup = GameRoundList.FirstOrDefault(g => g.GameRoundId == element.GameRoundId);
Debug.WriteLine($"Du valde raden med Runda {element.GameRoundId} och spelare: {element.ParticipantName}");
if (rbGroup != null)
{
_objectMessage.CurrentGroup = rbGroup;
await Shell.Current.GoToAsync("//RoundRunningView");
goneOk = true;
}
return goneOk;
}
[RelayCommand]

View File

@ -10,18 +10,22 @@ public partial class RoundRunningView : ContentPage
InitializeComponent();
ViewModel = viewModel;
ViewModel.RebuildRequested += ViewModel_RebuildRequested;
this.Loaded += OnPageLoaded;
}
private void OnPageLoaded(object? sender, EventArgs e)
{
ViewModel.Get();
}
protected override void OnAppearing()
{
base.OnAppearing();
BindingContext = ViewModel;
ViewModel.Get();
//BuildScoreGrid(ViewModel.PlayerColumns); // <-- h<>r bygger du layouten
}
private void ViewModel_RebuildRequested(object? sender, EventArgs e)
{
BuildScoreGrid(ViewModel.PlayerColumns); // <-- h<>r bygger du layouten