This is a migrated thread and some comments may be shown as answers.

Cannot compile InputBox with await method

4 Answers 44 Views
InputPrompt
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Domi
Top achievements
Rank 1
Domi asked on 06 Jan 2014, 04:07 PM

Hi,

I need to wait that a user enter some valuesin an RadInputPrompt using the following code :

InputPromptClosedEventArgs args = await RadInputPrompt.ShowAwait(inputBoxTitle, MessageBoxButtons.OKCancel);

however, I can't compile it and receive the following message :

Error 1 The 'await' operator can only be used within an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task'. D:\DISK_C\Windows Phone\Telerik\Samples\Domi_InputPrompt_8\MainPage.xaml.cs 58 51 _CustomMessageBox

Error 2 'Telerik.Windows.Controls.RadInputPrompt' does not contain a definition for 'ShowAwait' D:\DISK_C\Windows Phone\Telerik\Samples\Domi_InputPrompt_8\MainPage.xaml.cs 58 72 _CustomMessageBox

I'm using VS  2012 and have included Telerik.Windows.Controls.Primitives & Telerik.Windows.Core for WP8 as said in the documentation.

Any help will be very appreciated.

Sincerly,

Domi.



4 Answers, 1 is accepted

Sort by
0
Ivo
Telerik team
answered on 08 Jan 2014, 11:08 AM
Hello,
What you need to do is just to add a "async" modifier in front of the method into which you are using "await".

Regards,
Ivo
Telerik
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
0
Kay
Top achievements
Rank 1
answered on 13 May 2014, 07:27 AM
Ivo, not sure what you mean.

I have the same problem with the code like this taken from the documentation http://www.telerik.com/help/windows-phone/radinputprompt-gettingstarted.html. Getting the same error above.

​private void Button_Tap(object sender, RoutedEventArgs e)
{
Style textBoxStyle = new System.Windows.Style(typeof(RadTextBox));
textBoxStyle.Setters.Add(new Setter(RadTextBox.InputScopeProperty, "digits"));
string messageTitle = "How much is the bill?";
string message = "Please enter the amount of your meal";
InputPromptClosedEventArgs args = ShowPrompt(textBoxStyle, messageTitle, message);
amountEntered.Text = args.ToString();
}

private async Task<InputPromptClosedEventArgs> ShowPrompt(Style textBoxStyle, string messageTitle, string message)
{
return await RadInputPrompt.ShowAsync(messageTitle, MessageBoxButtons.OKCancel, message, InputMode.Text, textBoxStyle);
}
0
Todor
Telerik team
answered on 13 May 2014, 11:19 AM
Hi Kay,

You need to also add async modifier to the Button_Tap event handler:

private async void Button_Tap(object sender, RoutedEventArgs e)
{
    Style textBoxStyle = new System.Windows.Style(typeof(RadTextBox));
    textBoxStyle.Setters.Add(new Setter(RadTextBox.InputScopeProperty, "digits"));
    string messageTitle = "How much is the bill?";
    string message = "Please enter the amount of your meal";
    InputPromptClosedEventArgs args = await ShowPrompt(textBoxStyle, messageTitle, message);
    amountEntered.Text = args.ToString();
}
 
private async Task<InputPromptClosedEventArgs> ShowPrompt(Style textBoxStyle, string messageTitle, string message)
{
    return await RadInputPrompt.ShowAsync(messageTitle, MessageBoxButtons.OKCancel, message, InputMode.Text, textBoxStyle);
}

Let me know if you need further assistance.

Regards,
Todor
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Kay
Top achievements
Rank 1
answered on 14 May 2014, 02:36 AM
Works, thank you!
Tags
InputPrompt
Asked by
Domi
Top achievements
Rank 1
Answers by
Ivo
Telerik team
Kay
Top achievements
Rank 1
Todor
Telerik team
Share this question
or