Disable popup when RadioGroup item is selected

Using awesome MonoTouch.dialog in some of my projects is now a question. I have a RadioGroup that I use to let the user select their initial state, States is a string array.

    public static RootElement CreateStates ()
    {
        return new RootElement ("State", new RadioGroup (0)) 
        {
            new Section ("Choose State")
            {
                from x in States
                   select (Element) new RadioElement (x) 
            }
        };
    }

This works fine, and when I select a state, a pop-up window appears and I select my state, but then I need to press the "Back" button on the navigation bar to return to the main screen. Is there a way for the popup to decline when I select a selection? Clicking the back button is annoying. Or am I just misusing this solution?

My first thought was to subclass RadioElement and catch the selected event, but then I was still not sure how to reject the automatic selection pop-up?

+5
source share
1 answer

, , "" , . RadioElement Selected - , , , - , , , - .

public class MyRadioElement : RadioElement {
    // Pass the caption through to the base constructor.
    public MyRadioElement (string pCaption) : base(pCaption) {
    }

    // Fire an event when the selection changes.
    // I use this to flip a "dirty flag" further up stream.
    public override void Selected (
        DialogViewController pDialogViewController, 
        UITableView pTableView, NSIndexPath pIndexPath) {
        // Checking to see if the current cell is already "checked"
        // prevent the event from firing if the item is already selected.  
        if (GetActiveCell().Accessory.ToString().Equals(
            "Checkmark",StringComparison.InvariantCultureIgnoreCase)) {
            return;
        }

        base.Selected (pDialogViewController, pTableView, pIndexPath);

        // Is there an event mapped to our OnSelected event handler?
        var selected = OnSelected;

        // If yes, fire it.
        if (selected != null) {
            selected (this, EventArgs.Empty);
        }

        // Close the dialog.
        pDialogViewController.DeactivateController(true);
    }

    static public event EventHandler<EventArgs> OnSelected;
}
+13

All Articles