MicrosoftDocs / WindowsCommunityToolkitDocs

Creative Commons Attribution 4.0 International
179 stars 156 forks source link

Eyedropper example #686

Open ignatvs opened 1 year ago

ignatvs commented 1 year ago

There is something missing in the code examples:

var eyedropper = new Eyedropper(); var color = await eyedropper.Open();

it gives Error CS4033 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'. EyesDrpperApp


Document Details

using Microsoft.Toolkit.Uwp.UI.Controls; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls;

// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409

namespace EyesDrpperApp { ///

/// An empty page that can be used on its own or navigated to within a Frame. /// public sealed partial class MainPage : Page { public MainPage() { this.InitializeComponent(); Load(); }

    private void Load() 
    {
        var eyedropper = new Eyedropper();
        var color = await eyedropper.Open();
    }
}

}

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.

michael-hawker commented 1 year ago

@ignatvs as the error message says, you need to make your method async to use the await for the async method on the EyeDropper.