PopulatingEventArgs.Cancel Property


Gets or sets a value that indicates whether the Populating event should be canceled.

Namespace:  System.Windows.Controls
Assembly:  System.Windows.Controls.Input (in System.Windows.Controls.Input.dll)

public bool Cancel { get; set; }

Property Value

Type: System.Boolean
true to cancel the event, otherwise false. The default is false.

If the event is canceled, by setting the Cancel property to true, the AutoCompleteBox will not automatically populate the selection adapter that is contained in the drop-down. In this case, if you want possible matches to appear, you must provide the logic for populating the selection adapter.

The following code example demonstrates how to handle the Populating event and populate the AutoCompleteBox manually. This code example sets PopulatingEventArgs.Cancel property to true to stop auto-population and then calls PopulateComplete when the manual population operation is complete. This code example requires a reference to the System.Windows.Controls.Input assembly.

    // Handle the Populating event, but cancel it. Make the call to the web service.
    private void AutoCompleteBox_Populating(object sender, PopulatingEventArgs e)
        e.Cancel = true;

    // Call the topic service at the live search site.
    WebClient wc;
    private void CallToWebService()
        wc = new WebClient();
        wc.DownloadStringAsync(new Uri
            ("http://api.search.live.net/qson.aspx?query=" + myACB.SearchText +
        wc.DownloadStringCompleted +=
            new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);

    void wc_DownloadStringCompleted(object sender,
        DownloadStringCompletedEventArgs e)
        if (e.Error != null)

        List<string> data = new List<string>();
            JsonObject jso = ((JsonObject)JsonObject.Parse(e.Result))
                ["SearchSuggestion"] as JsonObject;
            string originalSearchString = jso["Query"];
            if (originalSearchString == myACB.SearchText)
                foreach (JsonObject suggestion in (JsonArray)jso["Section"])

                // Diplay the AutoCompleteBox drop down with any suggestions
                myACB.ItemsSource = data;
        catch { }

   <StackPanel x:Name="LayoutRoot" Background="White" Orientation="Horizontal">
    <TextBlock Text="News Topic:" HorizontalAlignment="Left"  VerticalAlignment="Center"/>
    <sdk:AutoCompleteBox VerticalAlignment="Center" HorizontalAlignment="Right" Height="30" 
        Width="100" MinimumPopulateDelay="200" MinimumPrefixLength="3" x:Name="myACB" Populating="AutoCompleteBox_Populating" />


Supported in: 5, 4, 3

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions