Kristian Espitia
Kristian Espitia

Reputation: 25

Refresh Page PopAsync()

I have a screen that captures digital signature which, when saving or returning, executes a postasync or postmodalasync when the screen returns to me does not reload. How can I make the page reload or refresh?

 <Grid BackgroundColor="WhiteSmoke" Padding="0" RowSpacing="0" VerticalOptions="StartAndExpand">
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <ContentView Margin="10,0,10,5" Padding="0" BackgroundColor="LightGray" HeightRequest="500">
                    <StackLayout Padding="5,0,5,5" BackgroundColor="White" Spacing="1">
                        <Label 
                Text="Firma Policia Que Realizo Visita"
                HorizontalOptions="Center"
                TextColor="Black" 
                FontSize="Large" 
                FontAttributes="Bold"

                 />

                    <Frame  HasShadow="true" 
                         Padding="8"
                        VerticalOptions="CenterAndExpand">
                        <signature:SignaturePadView  
                            x:Name="SignatureView" 

                            BindingContext="{Binding SignatureView}"
                            WidthRequest="280"
                        HeightRequest="300"
                            CaptionText="" 
                            CaptionTextColor="Blue" 
                            ClearText=""
                            PromptText=""
                            PromptTextColor="Green" 
                            BackgroundColor="WhiteSmoke" 
                            SignatureLineColor="Black" 
                            StrokeWidth="3" 
                            StrokeColor="Black" />
                    </Frame>
                </StackLayout>
                </ContentView>


        </Grid>


        <StackLayout Orientation="Horizontal" Padding="2" Spacing="2">
            <Button 
                    HorizontalOptions="FillAndExpand"
                    HeightRequest="40"                
                    Text="Guardar"
                    TextColor="{x:StaticResource WhiteColor}"
                    FontSize="Small"
                    VerticalOptions="Center"
                    BackgroundColor="{x:StaticResource GreenButton}"
                 Clicked="Button_Clicked">

            </Button>
            <Button                  
                    HorizontalOptions="FillAndExpand"
                    HeightRequest="40"                
                    Text="Limpiar"
                    TextColor="{x:StaticResource WhiteColor}"
                    FontSize="Small"
                    VerticalOptions="Center"
                    BackgroundColor="{x:StaticResource SicoqYellowColor}"
                   Clicked="Button_Clicked_1">
            </Button>


        </StackLayout>

This is the viewmodel which makes the backbuttoncommand service

public Task RemoveLastModalFromBack(object parameter,bool animated = false)
    {
        var mainPage = Application.Current.MainPage as NavigationView;
        if (mainPage != null)
        {
            mainPage.Navigation.PopAsync(animated);
        }

        return Task.FromResult(true);
    }

This is the ViewModel which receives the signature data

 private async Task BackButton()
    {

        try
        {
            IsBusy = true;



            await NavigationService.RemoveLastModalFromBack(str3);

            o


        }
        catch (Exception e)
        {
            IsBusy = false;
            // await DialogService.DisplayAlertAsync("Error", e.Message, "Aceptar");

        }
        finally
        {
            IsBusy = false;
        }
    }

The digital signature master page is digital signatures when you save or return the digital signatures page to reload

Upvotes: 1

Views: 1912

Answers (1)

Leon Lu
Leon Lu

Reputation: 9244

Do you want to achieve the result like following GIF? enter image description here

If so, you can use MessagingCenter to achieve that.

We can use send method of MessagingCenter, Here is my code in the Button click event of SignaturesPage,Use the MessagingCenter to send the data to the MainPage.

     private async void Button_Clicked(object sender, EventArgs e)
    {
       //get stream of Signatures  from the pad
        Stream image = await SignaturePad.GetImageStreamAsync(SignatureImageFormat.Png);
        MessagingCenter.Send<Stream>(image, "Image");
        await Navigation.PopAsync();
    }

In the MainPage, I layout have Image to wait the stream from the SignaturesPage.

     <StackLayout>
    <!-- Place new controls here -->
    <Frame BorderColor="Orange"
           CornerRadius="10"
           HasShadow="True">
        <Button AutomationId="Mybutton" Text="Save" x:Name="Mybutton" HorizontalOptions="CenterAndExpand" Clicked="Mybutton_Clicked"/>
    </Frame>
    <Frame BorderColor="Orange"
           CornerRadius="10"
           HasShadow="True">
        <Image x:Name="MyImage" HeightRequest="500" WidthRequest="400"/>
    </Frame>


</StackLayout>

Here is my background code in the MainPage.

   public partial class MainPage : ContentPage
  {
    public MainPage()
    {
        InitializeComponent();

        MessagingCenter.Subscribe<Stream>(this, "Image", (arg) =>
        {
            MyImage.Source = ImageSource.FromStream(() => arg);

        });

    }

    protected override void OnAppearing()
    {
        base.OnAppearing();
    }
    private  void Mybutton_Clicked(object sender, EventArgs e)
    {

        Navigation.PushAsync(new SignaturesPage());
    }
}

Upvotes: 1

Related Questions