| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- using System;
- using Syncfusion.XForms.PopupLayout;
- using Xamarin.Forms;
- namespace InABox.Mobile
- {
- public abstract class MobileView<TViewModel> : BaseMobileView
- where TViewModel : class, IMobileViewModel
- {
- private static readonly BindableProperty ViewModelProperty =
- BindableProperty.Create(
- nameof(ViewModel),
- typeof(TViewModel),
- typeof(MobileView<TViewModel>),
- null
- );
-
- public TViewModel ViewModel
- {
- get => (TViewModel)GetValue(ViewModelProperty);
- set
- {
- if (ViewModel != null)
- ViewModel.Loaded -= ViewModel_OnLoaded;
-
- SetValue(ViewModelProperty,value);
-
- if (ViewModel != null)
- ViewModel.Loaded += ViewModel_OnLoaded;
- }
- }
- protected override void DoBindingContextChanged()
- {
- ViewModel = BindingContext as TViewModel;
- Refresh();
- }
-
- private void ViewModel_OnLoaded(object sender, MobileViewModelLoadedEventArgs args)
- {
- Refresh();
- }
- public abstract void Refresh();
-
- public event MobileViewChangedEvent Changed;
- protected void DoChanged(string property)
- => Changed?.Invoke(this, new MobileViewChangedEventArgs(property));
-
- private readonly SfPopupLayout _popup = new SfPopupLayout();
-
- protected void ShowPopup(Func<View> view, int height = 500, int width = 300, int padding = 10)
- {
- _popup.PopupView.HeightRequest = height;
- _popup.PopupView.WidthRequest = width;
- _popup.PopupView.ShowHeader = false;
- _popup.PopupView.ShowFooter = false;
- _popup.PopupView.ContentTemplate = new DataTemplate(() =>
- {
- Grid grid = new Grid() { Margin = padding, Padding = padding};
- grid.Children.Add(view());
- return grid;
- });
- _popup.Show();
- }
- protected void DismissPopup()
- {
- _popup.Dismiss();
- }
- }
- }
|