Created
November 26, 2020 09:09
-
-
Save tkouba/5e9f7386dc261b5e3d4ee0106938ce04 to your computer and use it in GitHub Desktop.
Show indicator workaround for Xamarin.Forms.PageIs.IsBusy
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
// Android MainActivity | |
using Android.App; | |
using Android.Content.PM; | |
using Android.OS; | |
using AndroidHUD; // https://github.com/redth-org/AndHUD | |
namespace ThemingDemo.Droid | |
{ | |
[Activity(Label = "ThemingDemo", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)] | |
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity | |
{ | |
internal static MainActivity Instance { get; private set; } | |
protected override void OnCreate(Bundle savedInstanceState) | |
{ | |
TabLayoutResource = Resource.Layout.Tabbar; | |
ToolbarResource = Resource.Layout.Toolbar; | |
base.OnCreate(savedInstanceState); | |
Instance = this; | |
global::Xamarin.Forms.Forms.Init(this, savedInstanceState); | |
// Register message subscription | |
Xamarin.Forms.MessagingCenter.Subscribe<Xamarin.Forms.Page, bool>(this, Xamarin.Forms.Page.BusySetSignalName, OnBusySet); | |
LoadApplication(new App()); | |
} | |
// Show busy indicator | |
int busyCount = 0; | |
void OnBusySet(Xamarin.Forms.Page sender, bool enabled) | |
{ | |
busyCount = System.Math.Max(0, enabled ? busyCount + 1 : busyCount - 1); | |
if (busyCount == 0) | |
{ | |
AndHUD.Shared.Dismiss(Instance); | |
} | |
else | |
{ | |
AndHUD.Shared.Show(Instance, "IsBusy ...", maskType: MaskType.Clear); | |
} | |
} | |
} | |
} |
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
// WPF MainWindow | |
using System; | |
using Xamarin.Forms; | |
using Xamarin.Forms.Platform.WPF; | |
namespace ThemingDemo.WPF | |
{ | |
/// <summary> | |
/// Interaction logic for MainWindow.xaml | |
/// </summary> | |
public partial class MainWindow : FormsApplicationPage | |
{ | |
public MainWindow() | |
{ | |
InitializeComponent(); | |
Forms.Init(); | |
// Register message subscription | |
MessagingCenter.Subscribe<Xamarin.Forms.Page, bool>(this, Xamarin.Forms.Page.BusySetSignalName, OnBusySet); | |
LoadApplication(new ThemingDemo.App()); | |
} | |
// Show busy indicator | |
int busyCount = 0; | |
void OnBusySet(Xamarin.Forms.Page sender, bool enabled) | |
{ | |
busyCount = Math.Max(0, enabled ? busyCount + 1 : busyCount - 1); | |
if (busyCount == 0) | |
{ | |
if (System.Windows.Application.Current.MainWindow is FormsWindow window) | |
{ | |
window.HideContentDialog(); | |
} | |
} | |
else | |
{ | |
if (System.Windows.Application.Current.MainWindow is FormsWindow window) | |
{ | |
window.ShowContentDialog(new FormsContentDialog() | |
{ | |
// Use alternative progress indicator | |
//Content = new System.Windows.Controls.ProgressBar() { IsIndeterminate = true, Height = 20 }, | |
Content = new Xamarin.Forms.Platform.WPF.Controls.FormsProgressRing() { IsActive = true }, | |
Title = "IsBusy ..." | |
}); | |
} | |
} | |
} | |
} | |
} |
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
Application.Current.MainPage.IsBusy = true; | |
await System.Threading.Tasks.Task.Delay(5000); | |
Application.Current.MainPage.IsBusy = false; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment