Auto Complete Box in Silverlight



The AutoCompleteBox in Silverlight is used to complete the word automatically in a text box.

Xaml page for AutoCompleteBox:

Tools to be used:

AutoCompleteBox, TextBlock :Just drag and place autocomplete box from tool box to source page.
<navigation:Page xmlns:input="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input"  x:Class="ControlSamples.Page1"
           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"
           xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
           xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"                      d:DesignWidth="640" d:DesignHeight="480" Title="Page1 Page">
    <Grid x:Name="LayoutRoot">
<
input:AutoCompleteBox Name="MyAutoComplete" ValueMemberBinding="{Binding Caption}" HorizontalAlignment="Left" VerticalAlignment="Top" Populating="AutoCompleteBox_Populating" MinWidth="50" MaxHeight="500" MinHeight="5"  MaxWidth="500"  Width="250" Height="25" IsTextCompletionEnabled="True" >
            <input:AutoCompleteBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Caption}"></TextBlock>                  
               
</DataTemplate>           
           
</input:AutoCompleteBox.ItemTemplate>
        </input:AutoCompleteBox>

    </Grid>

</navigation:Page>

Used Properties in AutoCompleteBox:

  1. Name: Name of the control.
     

  2. ValueMemberBinding: A field which has to be bound in an AutoCompleteBox.
     

  3. Horizontal Alignment: Aligns the control's left position.
     

  4. Vertical Alignment: Aligns the control's right position.
     

  5. Width: Width of the control
     

  6. Height: Height of the control
     

  7. MinWidth: The control size which is not decreased below this width.
     

  8. MinHeight: The control size which is not decreased below this height.
     

  9. MaxWidth: The control size which is not increased above this width
     

  10. MaxHeight: The control size which is not increased above this height.
     

  11. IsTextCompletedEnabled: here can set text complete enable to true or false
     

  12. Populating: is fired when typeing a letter.

C#:

void c_GetFirstpassYieldSummaryDetailsCompleted(object sender, ControlSamples.ServiceReference1.GetFirstpassYieldSummaryDetailsCompletedEventArgs e)
        {
            MyAutoComplete.ItemsSource = e.Result.FirstpassYieldSummaryindex;
            MyAutoComplete.PopulateComplete();
       }

         private void AutoCompleteBox_Populating(object sender, PopulatingEventArgs e)
        {
            var obj= new ControlSamples.ServiceReference1.Service1Client();
            obj.GetFirstpassYieldSummaryDetailsCompleted += new EventHandler<ControlSamples.ServiceReference1.GetFirstpassYieldSummaryDetailsCompletedEventArgs>(c_GetFirstpassYieldSummaryDetailsCompleted);
            obj.GetFirstpassYieldSummaryDetailsAsync();
        }
 

Up Next
    Ebook Download
    View all
    Learn
    View all