Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Delegate Callback to pass value from the Rg pop up window to the parent. #51

Closed
msmrajesh opened this issue Oct 21, 2016 · 2 comments

Comments

@msmrajesh
Copy link

msmrajesh commented Oct 21, 2016

Hi,

I am having a situation similar to this #14

I have a Entry control on a content form and on tap event I am showing the Rg pop up window.

In this Rg pop up window I have a listview that is populated from a database. When the user selects a value from the listview, I want to pass this selected value back to the content form. As suggested by you in the thread mentioned above , I am using call back delegates to pass the value.

This is how i defined the code.

Content form that hosts the entry control.

   `//Declaring the delegate to pass the value from SearchPicker to the control that calls it
    public delegate void AddItemDelegate(string item);
  //handle the tap event of the entry control.
   var frmSearchPicker = new SearchPicker(passvalue);
   frmSearchPicker.AddItemCallback = new AddItemDelegate(this.AddItemCallBackFn);
   Navigation.PushPopupAsync(new SearchPicker(passvalue));`

Rg Popup control that hosts the listview

public MainForm.AddItemDelegate AddItemCallback;      

//the tap event of the listview control inside the Rg popup control.
private void listView_OnSelected(Object sender, SelectedItemChangedEventArgs args)
        {
            if(args.SelectedItem != null)
            {
                Country itm = (Country)args.SelectedItem;
                getSelectedCountry = itm.Name.ToString();
                AddItemCallback(getSelectedCountry);
                //AddItemCallback?.Invoke(getSelectedCountry);
            }
        }

The problem is that the debugger breaks on the line

AddItemCallback(getSelectedCountry); with this exception.

System.NullReferenceException: Object reference not set to an instance of an object.

Please let me know how to make it work correctly so that I can pass the value from the Rg popup control back to the parent form that calls it.

Thanks,

Rajesh.

@rotorgames
Copy link
Owner

@msmrajesh Hi. You have created new contructor for PushPopupAsync it is problem.

try it:

var frmSearchPicker = new SearchPicker(passvalue);
 frmSearchPicker.AddItemCallback = new AddItemDelegate(this.AddItemCallBackFn);
 Navigation.PushPopupAsync(frmSearchPicker);`

@msmrajesh
Copy link
Author

Hi @rotorgames Thanks a lot for helping out.
Rajesh.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants