How to: Call a Page Function

This example shows how to call a page function from a Extensible Application Markup Language (XAML) page.

Example

You can navigate to a page function using a uniform resource identifier (URI), just as you can when you navigate to a page. This is shown in the following example.

// Navigate to a page function like a page
Uri pageFunctionUri = new Uri("GetStringPageFunction.xaml", UriKind.Relative);
this.NavigationService.Navigate(pageFunctionUri);
' Navigate to a page function like a page
Dim pageFunctionUri As New Uri("GetStringPageFunction.xaml", UriKind.Relative)
Me.NavigationService.Navigate(pageFunctionUri)

If you need to pass data to the page function, you can create an instance of it and pass the data by setting a property. Or, as the following example shows, you can pass the data using a non-default constructor.

<Page x:Class="UsingPageFunctionsSample.CallingPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="CallingPage"
    >
    <Hyperlink Name="callPageFunctionHyperlink" Click="callPageFunctionHyperlink_Click">Call Page Function</Hyperlink>
</Page>
void callPageFunctionHyperlink_Click(object sender, RoutedEventArgs e)
{
    // Call a page function
    GetStringPageFunction pageFunction = new GetStringPageFunction("initialValue");
    this.NavigationService.Navigate(pageFunction);
}
Private Sub callPageFunctionHyperlink_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
	' Call a page function
	Dim pageFunction As New GetStringPageFunction("initialValue")
	Me.NavigationService.Navigate(pageFunction)
End Sub

See Also

PageFunction<T>