How to: Call a Page Function

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


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);
' Navigate to a page function like a page
Dim pageFunctionUri As New Uri("GetStringPageFunction.xaml", UriKind.Relative)

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-parameterless constructor.

<Page x:Class="UsingPageFunctionsSample.CallingPage"
    <Hyperlink Name="callPageFunctionHyperlink" Click="callPageFunctionHyperlink_Click">Call Page Function</Hyperlink>
void callPageFunctionHyperlink_Click(object sender, RoutedEventArgs e)
    // Call a page function
    GetStringPageFunction pageFunction = new GetStringPageFunction("initialValue");
Private Sub callPageFunctionHyperlink_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
    ' Call a page function
    Dim pageFunction As New GetStringPageFunction("initialValue")
End Sub

See also