[Silverlight] Silverlight et Bing
Depuis peu le SDK pour Bing vient de sortir ! Vous pouvez maintenant intégrer un moteur de recherche exploitant Bing dans vos applications Silverlight.
Direction http://silverbing.codeplex.com/ pour télécharger le SDK.
Ce framework nous met à disposition les méthodes pour faire une recherche mais aussi les conteneurs pour les afficher:
- Le StackView
- Le TileView
- Le CloudView
- Le BlandCloudView
Avant de commencer votre développement, inscrivez vous sur le site http://www.bing.com/developers pour recevoir un ID d’application cliente.
Comment créer notre projet ? Après avoir démarré un nouveau projet Silverlight , ajoutez les références à Microsoft.Bing.Data.dll et System.Windows.Controls.Views.Toolkit pour les conteneurs.
1: <StackPanel x:Name="LayoutRoot">
2: <views:StackView x:Name="stk" Width="400" Height="400">
3: <views:StackView.ItemTemplate>
4: <DataTemplate>
5: <TextBlock Text="{Binding Path=Title}"/> 6: </DataTemplate>
7: </views:StackView.ItemTemplate>
8: </views:StackView>
9:
10: <TextBox x:Name="txt" Width="100" Height="100" />
11: <Button Content="Recherche !" Click="Button_Click" />
12: </StackPanel>
Et le code behind:
1: private void Button_Click(object sender, RoutedEventArgs e)
2: { 3: //On bind déjà la collection qu'on remplira de façon asynchrone
4: stk.ItemsSource = SearchEnvironment.Default.Results;
5: //Event de base
6: //SearchEnvironment.Default.SearchStarted += new EventHandler(OnSearchStarted);
7: //SearchEnvironment.Default.SearchCompleted += new EventHandler<SearchResponseEventArgs>(OnSearchCompleted);
8: //SearchEnvironment.Default.Error += new EventHandler<ErrorEventArgs>(OnSearchError);
9:
10: SearchEnvironment.Default.PageSize = 20;
11: //ID de votre application
12: SearchEnvironment.Default.ApplicationId = "ID";
13: //Type de recherche (images, vidéos...)
14: SearchEnvironment.Default.MediaType = SearchMedia.Web;
15: //Lancement de la recherche
16: SearchEnvironment.Default.BeginSearch(txt.Text);
17:
18: }
