Wired up DisplayAlert results so we can now specify an accept/cancel action and retrieve the result

This commit is contained in:
Andrew Hoefling 2017-11-17 22:39:11 +00:00
parent 404201d876
commit 2b8ce39a5c
2 changed files with 11 additions and 2 deletions

View File

@ -59,6 +59,7 @@ namespace Ooui.Forms
{ {
ClassName = "btn btn-default" ClassName = "btn btn-default"
}; };
_cancelButton.Clicked += (s, e) => SetResult(false);
footer.AppendChild(_cancelButton); footer.AppendChild(_cancelButton);
@ -69,13 +70,20 @@ namespace Ooui.Forms
ClassName = "btn btn-default" ClassName = "btn btn-default"
}; };
_acceptButton.Clicked += (s, e) => SetResult(true);
footer.AppendChild(_acceptButton); footer.AppendChild(_acceptButton);
} }
content.AppendChild(footer); content.AppendChild(footer);
} }
Element.AppendChild(content); Element.AppendChild(content);
void SetResult(bool result)
{
arguments.SetResult(result);
}
} }
public event TargetEventHandler Clicked public event TargetEventHandler Clicked

View File

@ -15,7 +15,8 @@ namespace Samples
public async void OnButtonClicked(object sender, EventArgs args) public async void OnButtonClicked(object sender, EventArgs args)
{ {
await DisplayAlert("Alert Message", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa.", "OK"); var result = await DisplayAlert("Alert Message", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa.", "YES", "NO");
await DisplayAlert("Alert Response", $"You selected value: {result}", "OK");
} }
} }
} }