Last active
July 20, 2019 12:25
-
-
Save QiMata/1a1e55afb91ebdfaf8280dd3b7179136 to your computer and use it in GitHub Desktop.
A common base page for using IsBusy property to show a busy indicator.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8" ?> | |
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" | |
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | |
x:Class="LoadingPage" | |
x:Name="ContentPage"> | |
<ContentPage.Content> | |
<AbsoluteLayout> | |
<ContentView Content="{Binding Source={x:Reference ContentPage},Path=MainContent}" | |
HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" | |
AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All"> | |
</ContentView> | |
<!-- Your Busy Indicator (Check out syncfusion's busy indicator) --> | |
<ContentView Content="{Binding Source={x:Reference ContentPage}, Path=LoadingView}" | |
IsVisible="{Binding Source={x:Reference ContentPage},Path=IsBusy}" | |
AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All" /> | |
</AbsoluteLayout> | |
</ContentPage.Content> | |
</ContentPage> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ContentProperty(nameof(MainContent))] | |
[XamlCompilation(XamlCompilationOptions.Compile)] | |
public partial class LoadingPage : ContentPage | |
{ | |
public LoadingPage() | |
{ | |
InitializeComponent(); | |
} | |
public static readonly BindableProperty MainContentProperty = | |
BindableProperty.Create(nameof(MainContent), typeof(View), typeof(LoadingPage)); | |
public static readonly BindableProperty LoadingContentProperty = | |
BindableProperty.Create(nameof(LoadingView), typeof(View), typeof(LoadingPage)); | |
public View LoadingView | |
{ | |
get => (View) GetValue(LoadingContentProperty); | |
set => SetValue(LoadingContentProperty, value); | |
} | |
public View MainContent | |
{ | |
get { return (View) GetValue(MainContentProperty); } | |
set { SetValue(MainContentProperty, value); } | |
} | |
protected override void OnBindingContextChanged() | |
{ | |
base.OnBindingContextChanged(); | |
if (MainContent == null) | |
{ | |
return; | |
} | |
SetInheritedBindingContext(MainContent, BindingContext); | |
} | |
} |
The other pages in the application would inherit from BaseContentPage instead of Content page.
Instead of inheriting from BasePage we can also create a controltemplate like shown here http://surfy57.free.fr/?p=42
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @QiMata
How do you use this base page? Can you share usage of this LoadingPage?
Thanks.