In my last article AutoCompleteBox in Silverlight 4.0, the Data Source for the Autocomplete Box was an IEnumerable list. In this article we will work with a column value of table from SQL Server as Data Source for Autocomplete Box. Our approach would be
<UserControl xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" x:Class="SilverlightApplication4.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="400"> <Grid x:Name="LayoutRoot" Background="White"> <sdk:AutoCompleteBox x:Name="atcTextBox" ItemsSource="{Binding}" ValueMemberPath="CourseName" FilterMode="Contains" IsTextCompletionEnabled="True" Height="30" Margin="62,22,54,248"> <sdk:AutoCompleteBox.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding CourseName}" /> </DataTemplate> </sdk:AutoCompleteBox.ItemTemplate> </sdk:AutoCompleteBox> </Grid></UserControl>MainPage.Xaml.cs
using System;using System.Collections.Generic;using System.Windows.Controls;using SilverlightApplication4.ServiceReference1;namespace SilverlightApplication4{ public partial class MainPage : UserControl { List<Courses> lstCourses = null; public MainPage() { InitializeComponent(); Service1Client proxy = new Service1Client(); proxy.GetTitleToBindCompleted += new EventHandler<GetTitleToBindCompletedEventArgs>(proxy_GetTitleToBindCompleted); proxy.GetTitleToBindAsync(); } void proxy_GetTitleToBindCompleted(object sender, GetTitleToBindCompletedEventArgs e) { lstCourses = new List<Courses>(); var res = e.Result; foreach (var r in res) { lstCourses.Add(new Courses { CourseName = r.ToString() }); } atcTextBox.DataContext = lstCourses; } } }
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: