Aracılığıyla paylaş


Nasıl yapılır: Sayfa İşlevinden Dönme

Bu örnekte, bir sayfa işlevinden nasıl sonuç döndürüleceği gösterilmektedir.

Örnek

Bir sayfa işlevinden dönmek için öğesini çağırmanız OnReturn ve bir örneğini ReturnEventArgs<T>geçirmeniz gerekir.

<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));
    }
}
Partial Public Class GetStringPageFunction
    Inherits PageFunction(Of String)
    Public Sub New()
        InitializeComponent()
    End Sub

    Public Sub New(ByVal initialValue As String)
        Me.New()
        Me.stringTextBox.Text = initialValue
    End Sub

    Private Sub okButton_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
        ' Page function is accepted, so return a result
        OnReturn(New ReturnEventArgs(Of String)(Me.stringTextBox.Text))
    End Sub

    Private Sub cancelButton_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
        ' Page function is cancelled, so don't return a result
        OnReturn(New ReturnEventArgs(Of String)(Nothing))
    End Sub
End Class

Ayrıca bkz.