Silverlight SDK for Microsoft Bing
SearchEnvironment Class
OverviewMicrosoft.BingSearchEnvironment
Implements a singleton for aggregating observable data objects, search related events, global search settings and other common runtime resources.
Declaration Syntax
C#Visual BasicVisual C++
public class SearchEnvironment : DependencyObject, 
	INotifyPropertyChanged
Public Class SearchEnvironment _
	Inherits DependencyObject _
	Implements INotifyPropertyChanged
public ref class SearchEnvironment : public DependencyObject, 
	INotifyPropertyChanged
Members
All MembersMethodsPropertiesFieldsEvents



IconMemberDescription
AdultOption
Gets/Sets a value which indicates how Adult content screening will be handled.

AlwaysOpenInNewWindow
Gets/Sets a boolean value which determines if search results will always be opened in a new window when their activation links are clicked

ApiVersion
Gets/Sets a simple version for the Bind API to be used.

ApplicationId
Gets/Sets the application Id associated with the application. This ID is assigned via the Microsoft Bing management web interfaces for developers.

BeginSearch(String)
Begins an asynchronous search query

CheckAccess()()() (Inherited from DependencyObject.)
ClearValue(DependencyProperty) (Inherited from DependencyObject.)
CurrentPage
Gets a value which indicates the current page of the active search

Default
Gets the singleton instance of the SearchEnvironment type.

Dispatcher()()() (Inherited from DependencyObject.)
Equals(Object)
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Error
Event which fires when an error occurs during a search call

FileTypeFilter
Gets/Sets the file type filter used in web searches

GetAnimationBaseValue(DependencyProperty) (Inherited from DependencyObject.)
GetHashCode()()()
Serves as a hash function for a particular type.
(Inherited from Object.)
GetType()()()
Gets the Type of the current instance.
(Inherited from Object.)
GetValue(DependencyProperty) (Inherited from DependencyObject.)
HasActiveSearch
Gets a boolean value indicating whether a search is active

History
Gets the current SearchHistory for the active user.

HistoryDepth
Gets/Sets the maximum depth of the SearchHistory tracked by the SearchEnvironment.

HistoryDepthProperty
Identifies the HistoryDepth dependency property.

LocationOverride
Gets/Sets the location override used in searches. By default, the location is sensed by IP address - this value will cause the search to use a specific location instead.

Market
Gets/Sets a string indentifier for the global market targetted for search.

MediaType
Gets/Sets a value which determines the SearchMedia to use when executing searches.

NewsCategory
Gets/Sets the news category used in News searches

NewsSort
Gets/Sets the default news sorting used by news searches

OpenSearchResult(SearchResult, Boolean)
Opens a search result as content - If the search result links to a Silverlight supported format, then the result will be opened in a custom preview control. This includes Portable Networks Graphics images (.PNG), Joint Photgraphics Experts images (.JPG), which will be shown in an image preview Window control, and Windows Media Video which are shown in a video player window. All other types will act like a standard HTML hyperlink, opening the content in a window. The newWindow boolean arugment determines whether the content will be opened in a new window, or reuse the current window. The newWindow argument is ignored if the property AlwaysOpenInNewWindow is set to true.

PageBack()()()
Pages to the previous page, if possible, in the current search

PageCount
Gets a value which indicates how many pages are in the current SearchResults based on ResultCount and PageSize.

PageFirst()()()
Pages to the first page in the current search

PageLast()()()
Pages to the last page, if possible, in the current search

PageNext()()()
Pages to the next page, if possible, in the current search

PageSize
Gets/Sets a value which defines the number of elements per page (Page Size)

PageSizeProperty
Identifies the PageSize dependency property.

PageTo(UInt32)
Pages the current search to a specific page

PhonebookSort
Gets/Sets the default sorting used by Phonebook searches

PropertyChanged
Event which fires when Dependency Properties have changed.

QueryTimeElapsed
Gets the TimeSpan value from the QueryTimeElapsed property. This returns the amountt of time consumed by the last search.

ReadLocalValue(DependencyProperty) (Inherited from DependencyObject.)
ResultCount
Gets/Sets a value which indicates how many total results were returned. This value can and will often be an approximation.

Results
Gets a collection of the current SearchResults.

SearchCompleted
Event which fires when a search is completed

SearchEngine
Gets an instance of an ISearchEngine which defines an in-process implementation of a search provider.

SearchStarted
Event which fires when a Search is begun

SearchStorage
Gets/Sets the ISearchStorage interface for the SearchEnvironment

SetValue(DependencyProperty, Object) (Inherited from DependencyObject.)
ToString()()()
Returns a String that represents the current Object.
(Inherited from Object.)
UILanguage
Gets/Sets a string indentifier for the UI language. This determines the formatting relative to language for the search results.

Remarks
SearchEnvironment is a DependencyObject and also implements INotifyPropertyChanged. This allows it to be used in binding syntax.
Examples

The Microsoft Bing SDK is very easy to use in terms of Xaml implementation and binding to the Search data itself. The SearchEnvironment singleton is where the bulk of the logic and data operations take place. This object is also a DependencyObject and implements INotifyPropertyChanged, which provides support for data binding.

To execute a search, you only need to create a SearchRequest, populate its Query property, and then insure that you have set the SearchMedia property on the SearchEnvironment. Then, call the method BeginSearch(String), insuring that you have provided a handler for SearchCompleted.

You should also bind any display controls - typically ItemsControl instances, such as ListBox etc - to the Results property. This property is of type SearchResults and is an observable collection. This means that you can data bind your ItemsControl instances in advance, like this:

CopyC#
//Assumes a ItemsControl named "MyList" exists...
MyList.ItemsSource = SearchEnvironment.Default.Results;

//Consume SearchEnvironment Events
SearchEnvironment.Default.SearchStarted += new EventHandler(OnSearchStarted);
SearchEnvironment.Default.SearchCompleted += new EventHandler<SearchResponseEventArgs>(OnSearchCompleted);
SearchEnvironment.Default.Error += new EventHandler<ErrorEventArgs>(OnSearchError);

//Begin the Search (Assume a TextBox named "QueryText" exists)
SearchEnvironment.Default.PageSize = 20;
SearchEnvironment.Default.MediaType = SearchMedia.Web;
SearchEnvironment.Default.BeginSearch(QueryText.Text);

This should be done prior to executing any searches. Then when a search completes, the Results collection will become populated, if there are avialable results, and your ItemsControl control will automatically data bind and use the asynchronous layout framework in the Silverlight runtime.

Inheritance Hierarchy
Object
DependencyObject
 SearchEnvironment
See Also

Assembly: Microsoft.Bing.Data (Module: Microsoft.Bing.Data) Version: 1.0.0.0 (1.0.0.0)