Код: Выделить всё
await Navigation.PushModalAsync(new OrderTabsPage(_userService, _services));
Код: Выделить всё
public partial class OrderTabsPage : TabbedPage
{
private readonly OrderViewModel _viewModel;
private bool _tabsInitialized = false;
public OrderTabsPage(IUserService userService, IServiceProvider services)
{
InitializeComponent();
_viewModel = new OrderViewModel { Order = order };
foreach (var child in Children)
{
if (child is ContentPage { Content: ContentView contentView } && contentView is IOrderTab tab)
{
tab.Initialize(user, services, _viewModel);
}
}
_tabsInitialized = true;
}
}
Код: Выделить всё
public partial class OrderMainTab : ContentView, IOrderTab
{
public Entry ItemCodeEntry => ItemCode;
public OrderMainTab()
{
InitializeComponent();
if (Parent is ContentPage contentPage)
{
contentPage.Appearing += OnParentPageAppearing;
}
else
{
PropertyChanged += (sender, e) =>
{
if (e.PropertyName == nameof(Parent) && Parent is ContentPage cp)
{
cp.Appearing += OnParentPageAppearing;
}
};
}
}
public void Initialize(User user, IServiceProvider services, OrderViewModel viewModel)
{
BindingContext = new OrderMainViewModel(user, services, viewModel, this.Navigation);
}
}
Код: Выделить всё
public partial class OrderMainViewModel : ObservableObject
{
[RelayCommand]
private async Task LookupOrder()
{
try
{
var changeOrderPage = new ChangeOrderPage(_db, _user, _orderViewModel.Order.Id);
MainThread.BeginInvokeOnMainThread(async () =>
{
await _navigation.PushModalAsync(changeOrderPage);
});
}
catch (Exception ex)
{
await Application.Current.MainPage.DisplayAlert("Error", ex.Message, "OK");
}
}
}
Код: Выделить всё
public class ChangeOrderMessage : ValueChangedMessage
{
public ChangeOrderMessage(Guid orderId) : base(orderId) { }
}
public partial class ChangeOrderPage : ContentPage
{
private bool _navigatingBack = false;
private async void OnPropertyChangedHandler(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(ChangeOrderViewModel.SelectedOrder))
{
var selected = ((ChangeOrderViewModel)BindingContext).SelectedOrder;
if (selected != null && !_navigatingBack)
{
_navigatingBack = true;
try
{
await dispatcher.DispatchAsync(async () =>
{
if (Navigation.ModalStack.Count > 0)
{
await Navigation.PopModalAsync();
}
});
}
catch (Exception ex)
{
Console.WriteLine($"Error closing modal: {ex}");
}
finally
{
_navigatingBack = false;
}
WeakReferenceMessenger.Default.Send(new ChangeOrderMessage(selected.OrderId));
}
}
}
}
< /code>
Пока все хорошо, нет ошибки. После того, как изменение dorderpage Код: Выделить всё
private async Task VerificationCheck(Order newOrder)
{
if (newOrder == null)
{
await App.Current.MainPage.DisplayAlert("Error", "Data tidak ditemukan.", "OK");
return false;
}
if (newOrder.IsPrint)
{
object result = await App.Current.MainPage.ShowPopupAsync(new PINConfirmationDialog(newOrder.Code));
if (result is string pin)
{
if (string.IsNullOrWhiteSpace(pin))
{
await App.Current.MainPage.DisplayAlert("Error", "PIN tidak valid.", "OK");
return false;
}
if (pin.Trim() != newOrder.Verification.Trim())
{
await App.Current.MainPage.DisplayAlert("Error", "PIN Salah. Mohon masukkan PIN yang benar.", "OK");
return false;
}
return true;
}
return false;
}
return true;
}
Код: Выделить всё
await _navigation.PushModalAsync(changeOrderPage);
< /code>
или просто обратно на главную страницу < /p>
await _avigation.PopModalAsync();
Код: Выделить всё
public OrderMainViewModel(User user, IServiceProvider services, OrderViewModel viewModel, INavigation navigation, Action focusItemCodeAction = null)
{
_user = user;
_services = services;
_orderViewModel = viewModel;
_navigation = navigation;
await App.Current.MainPage.DisplayAlert("Error", $"Modal stack count: {Application.Current.MainPage.Navigation.ModalStack.Count.ToString()}", "OK");
object result = null;
await MainThread.InvokeOnMainThreadAsync(async () =>
{
result = await App.Current.MainPage.ShowPopupAsync(new PINConfirmationDialog(newOrder.Code));
});
await App.Current.MainPage.DisplayAlert("Error", $"Modal stack count: {Application.Current.MainPage.Navigation.ModalStack.Count.ToString()}", "OK");
}
Подробнее здесь: https://stackoverflow.com/questions/796 ... alog-popup