Comment : obtenir la valeur de retour d'une fonction de page
Cet exemple indique comment obtenir le résultat renvoyé par une fonction de page.
Exemple
Pour obtenir le résultat renvoyé par une fonction de page, vous devez gérer le Return de la fonction de page appelée.
<Page x:Class="UsingPageFunctionsSample.CallingPage"
xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml"
Title="CallingPage"
>
<Hyperlink Name="callPageFunctionHyperlink" Click="callPageFunctionHyperlink_Click">Call Page Function</Hyperlink>
</Page>
Private Sub callPageFunctionAndReturnHyperlink_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
' Call a page function and hook up page function's return event to get result
Dim pageFunction As New GetStringPageFunction()
AddHandler pageFunction.Return, AddressOf GetStringPageFunction_Returned
Me.NavigationService.Navigate(pageFunction)
End Sub
Private Sub GetStringPageFunction_Returned(ByVal sender As Object, ByVal e As ReturnEventArgs(Of String))
' Get the result, if a result was passed.
If e.Result IsNot Nothing Then
Console.WriteLine(e.Result)
End If
End Sub
void callPageFunctionAndReturnHyperlink_Click(object sender, RoutedEventArgs e)
{
// Call a page function and hook up page function's return event to get result
GetStringPageFunction pageFunction = new GetStringPageFunction();
pageFunction.Return += new ReturnEventHandler<String>(GetStringPageFunction_Returned);
this.NavigationService.Navigate(pageFunction);
}
void GetStringPageFunction_Returned(object sender, ReturnEventArgs<String> e)
{
// Get the result, if a result was passed.
if (e.Result != null)
{
Console.WriteLine(e.Result);
}
}