Bob Gatto
Bob Gatto

Reputation: 115

Can I data bind a property defined in the popup-page class itself?

I have a popup page where I want to return a value from. So in its c# file I have the code looking like this:

public partial class SelectDb : PopupPage
{
    TaskCompletionSource<string> taskCompSrc;
    public Task<string> PopupDismissed => taskCompSrc.Task;
    public string RetVal {  get; set; }

    public SelectDb(List<string> lst)
    {
       InitializeComponent();
    }

    protected override void OnAppearing()
    {
        base.OnAppearing();
        taskCompSrc = new TaskCompletionSource<string>();
    }

    protected override void OnDisappearing()
    {
        base.OnDisappearing();
        taskCompSrc.SetResult(RetVal);
    }

and in my view code of the popup screen I have code that would call a command from the view model like this:

            <Button Text="Select"
                WidthRequest="100"
                TextColor="White"
                Command="{Binding SetConnCommand}"/>

In the SetConn method processing is done and the popup screen is closed.

So is it possible to somehow data bind the RetVal variable to the view model where SetConn is being called so RetVal can be set properly before the popup is closed?

Upvotes: 0

Views: 53

Answers (0)

Related Questions