第一次在silverlight上工作,想将AutoCompleteBox(通过网络服务)与图像拇指和图像标题绑定,将通过图像标题搜索,我可以绑定图像标题
工作流程
网络服务
[WebMethod] public List<imagedata> Searchimage(string s) { var db = new PetaPoco.Database("sales"); var list = from search in db.Query<imagedata>("select * from imagedata").ToList() where search.imgname.Contains(s) select search; return list.ToList<imagedata>() ; }
xml
<sdk:AutoCompleteBox x:Name="searchText" Populating="searchText_Populating" /> </StackPanel>
。CS
private void searchText_Populating(object sender, PopulatingEventArgs e) { mySoapClient proxy = new mySoapClient(); proxy.SearchimageCompleted += new EventHandler<SearchimageCompletedEventArgs>(proxy_ImageGetCompleted); proxy.SearchimageAsync(searchText.Text); } void proxy_ImageGetCompleted(object sender, SearchimageCompletedEventArgs e) { var searchResults = new List<imagedata>(e.Result); var data = new List<string>(); foreach (var x in searchResults) { data.Add(x.imgname); } searchText.ItemsSource = data; searchText.PopulateComplete(); }
想要为图像拇指和图像标题绑定图像 url,我应用以下过程
<sdk:AutoCompleteBox x:Name="searchText" Populating="searchText_Populating">
<sdk:AutoCompleteBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image x:Name="image1" Height="100" Width="100" Canvas.Left="0" Canvas.Top="0"></Image>
<TextBlock VerticalAlignment="Center" Margin="10 0 0 0" />
</StackPanel>
</DataTemplate>
</sdk:AutoCompleteBox.ItemTemplate>
如何将集合绑定到自动完成框的数据模板,我可以为此使用字典吗?如果是,那么我如何将其绑定到数据模板