[英]Refresh Page PopAsync()
我有一個捕獲數字簽名的屏幕,在保存或返回時,當屏幕返回給我時執行 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>
這是制作 backbuttoncommand 服務的視圖模型
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;
}
}
數字簽名母版頁是保存或返回數字簽名頁面重新加載時的數字簽名
如果是這樣,您可以使用MessagingCenter
來實現這一點。
我們可以使用MessagingCenter
send
方法,這是我在SignaturesPage
的 Button 點擊事件中的代碼,使用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());
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.