刷新页面PopAsync()

克里斯蒂安·埃斯皮蒂亚(Kristian Espitia)

我有一个捕获数字签名的屏幕,该屏幕在保存或返回时会在不返回屏幕的情况下执行postasync或postmodalasync。如何重新加载或刷新页面?

 <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>

这是使backbutton命令服务的视图模型

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);
    }

这是接收签名数据的ViewModel

 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;
        }
    }

保存或返回数字签名页面以重新加载时,数字签名母版页是数字签名

路Lu-MSFT

您是否想要获得像跟随GIF一样的结果? 在此处输入图片说明

如果是这样,您可以使用它MessagingCenter来实现。

我们可以使用的send方法MessagingCenter,这是我的Button单击事件中的代码SignaturesPage,使用MessagingCenter可以将数据发送到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();
    }

在MainPage中,我必须Image等待布局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>

这是我在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());
    }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章