Export (0) Print
Expand All

How to: Return from a Page Function

This example shows how to return a result from a page function.

To return from a page function, you need to call OnReturn and pass an instance of ReturnEventArgs<T>.


<PageFunction
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sys="clr-namespace:System;assembly=mscorlib" 
    x:Class="UsingPageFunctionsSample.GetStringPageFunction"
    x:TypeArguments="sys:String"
    Title="GetStringPageFunction">


...


</PageFunction>



public partial class GetStringPageFunction : PageFunction<String>
{
    public GetStringPageFunction()
    {
        InitializeComponent();
    }

    public GetStringPageFunction(string initialValue) : this()
    {
        this.stringTextBox.Text = initialValue;
    }

    void okButton_Click(object sender, RoutedEventArgs e)
    {
        // Page function is accepted, so return a result
        OnReturn(new ReturnEventArgs<string>(this.stringTextBox.Text));
    }

    void cancelButton_Click(object sender, RoutedEventArgs e)
    {
        // Page function is cancelled, so don't return a result
        OnReturn(new ReturnEventArgs<string>(null));
    }
}


Show:
© 2014 Microsoft