5using System.Threading.Tasks;
10 public class LazyView<T> : ContentView where T : View
12 public static readonly BindableProperty DelayMsProperty =
13 BindableProperty.Create(
21 get => (int)this.GetValue(DelayMsProperty);
22 set => this.SetValue(DelayMsProperty, value);
25 private bool isLoaded =
false;
30 this.Loaded += async (s, e) => await this.TryLoadAsync();
33 private async Task TryLoadAsync()
35 if (this.isLoaded)
return;
39 await Task.Delay(this.DelayMs);
43 if (PageOrView.BindingContext is
null)
44 PageOrView.BindingContext = this.BindingContext;
47 if (PageOrView is View v)
50 throw new InvalidOperationException($
"{typeof(T).Name} is not a View.");
Base class that references services in the app.
static IServiceProvider Provider
The service provider for the app. This is set before the app is started, and will be used to resolve ...