1

This is my ViewModel with bool and string property:

ViewModel : ValidatableBindableBase {
    private bool _isBusy;
    public bool IsBusy {
        get { return _isBusy; }
        set { SetProperty(ref _isBusy, value); }
    }

    private string _busyMessage;
    public string BusyMessage {
        get { return _busyMessage; }
        set { SetProperty(ref _busyMessage, value); }
    }

//Triggered when the button is clicked.
private async void Login() {
        ShowBusyOverlay("Signing in");
        // it will show if task.delay is added
        //await Task.Delay(5000);
        await loginService.SignIn();         
}

private async  void ShowBusyOverlay(string message) {
            IsBusy = true;
            BusyMessage = message;
    }
}

XAML: NOTE: on Windows 10 15063 Visibility can bind bool property without converter

<Grid Grid.RowSpan="3" Grid.ColumnSpan="3" Visibility="{Binding Path=IsBusy, UpdateSourceTrigger=PropertyChanged}">
        <Rectangle Fill="Black" Opacity="0.4" />
        <StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
            <ProgressRing IsActive="True" Width="40" Height="40"/>
            <TextBlock Text="{Binding BusyMessage}" FontSize="20" FontWeight="Thin"/>
        </StackPanel>
    </Grid>

Target:

enter image description here

It doesn't show the Grid fast enough , so It will navigate to other page without showing it , how can I show that loading/grid as soon as the it goes to my ShowBusyOverlay? and is it advisable?

Reaper
  • 61
  • 1
  • 1
  • 8

1 Answers1

1

how can I show that loading/grid as soon as the it goes to my ShowBusyOverlay?

By activating it synchronously and then giving the UI thread time to update the screen.

Example:

private async void Login() 
{
    BusyMessage = message;
    IsBusy = true;
    await Task.Delay( TimeSpan.FromSeconds( 10 ) );
    IsBusy = false;
}

If, however, whatever task you're doing asynchronously is over rather quickly (or executing synchronously), the busy overlay will just flash or not appear at all. I'd make it fade in and out instead of immediately appearing/disappearing to reduce the visibility/annoyingness of the flashing.

Haukinger
  • 10,420
  • 2
  • 15
  • 28