The assembly Microsoft.Bing.Data contains a complete implementation of the Bing API. It provides this runtime with a variety of interfaces which offer extensibility to the overall framework, which developers can use to alter the behavior of the Bing service framework without altering the source code.
The core of the implementation centers around the type SearchEnvironment. SearchEnvironment has some note-worthy implementation features.
SearchEnvironment is derived from System.Windows.DependencyObject and implements INotifyPropertyChanged. This means that developers can data bind control properties to properties of SearchEnvironment, using OneWay or TwoWay binding modes. This is very useful for controls like page size sliders. An example of this can be found in the Page.xaml.cs source for the Bind User control.

-
Data Bind to SearchEnvironment SearchResults collection
Example
CopyC#
//Data Bind (in advance) to SearchResults (ObservableCollection<T>) - Assumes a StackView named "MyStackView" exists MyStackView.ItemsSource = SearchEnvironment.Default.SearchResults; //Control will bind as this collection changes
-
Bind Events to Handlers
Example
CopyC#
//Consume SearchEnvironment Events SearchEnvironment.Default.SearchStarted += new EventHandler(OnSearchStarted); //Fires when a search is begun SearchEnvironment.Default.SearchCompleted += new EventHandler<SearchResponseEventArgs>(OnSearchCompleted); //Fires when a search completes successfully SearchEnvironment.Default.Error += new EventHandler<ErrorEventArgs>(OnSearchError); //Fires when a search fails (typically due to network conditions)
-
Set Behavior Properties of the SearchEnvironment
These include properties such as:
- PageSize: The page size for searches
- SearchMedia: Specifies which Bing feed to consume (for example, Web, Images, News, or Video).
Example
CopyC#
//Set SearchEnvironment Behavior SearchEnvironment.Default.PageSize = 20; //Could be a control binding SearchEnvironment.Default.SearchMedia = SearchMedia.Video; //Searching for Videos - this could be a control binding also - see Page.xaml in the sample
-
Execute a Search Asynchronously
To execute a search, all that is required is a search term or terms. These can and should typically be supplied by a TextBox.
Example
CopyC#
//Execute the Search (Assumes a TextBox control named 'QueryText' exists) SearchEnvironment.Default.BeginSearch(QueryText.Text);