This method creates an AutoCompleteBox object
private AutoCompleteBox criaAutoCompletBox()
{
AutoCompleteBox acBox = new AutoCompleteBox();
acBox.FilterMode = AutoCompleteFilterMode.ContainsOrdinal;
acBox.IsTextCompletionEnabled = true;
acBox.ValueMemberPath = "designacao";
acBox.SetValue(Grid.MinWidthProperty, 100.0);
acBox.SetValue(Grid.HeightProperty, 20.0);
acBox.SetValue(Grid.MarginProperty, new Thickness(5, 0, 0, 0));
return acBox;
}
After created the AutoCompleteBox, this code snippet make the set of ItemSource,but does not show the desired attribute, only shows a list of the type of instantiated object
void rptacb_geraTabelaDadosCompleted(object sender, ReportWriterService.geraTabelaDadosCompletedEventArgs e)
{
try
{
for (int i = 0; i < relatorio.FC_RELATORIO_PARAMETROS.Count; i++)
{
string tipo = relatorio.FC_RELATORIO_PARAMETROS.ElementAt(i).FCRP_TIPO;
AutoCompleteBox acb = ((System.Windows.Controls.AutoCompleteBox)(this.FindName(e.Result.campo)));
acb.ItemsSource = e.Result.tabela;
}
}
catch (Exception ex)
{
new IMessage(ex).Show();
Busy.appIsBusy(false);
}
}
I read on some forums, but found only one code in Xaml which is configured using the ItemTamplete, DataTemplate and TextBlock, but I do not how to do in C #.
<sdk:AutoCompleteBox Grid.Column="1" Margin="2,0" Height="23" FilterMode="Contains" Padding="0" ItemsSource="{Binding}" ValueMemberPath="designacao" Width="Auto" Name="acbPesqProduto" HorizontalAlignment="Stretch">
<sdk:AutoCompleteBox.ItemTemplate>
<DataTemplate>
<StackPanel FlowDirection="LeftToRight" Orientation="Horizontal">
<TextBlock Text="{Binding Path=designacao}" Margin="0,0,0,10"/>
</StackPanel>
</DataTemplate>
</sdk:AutoCompleteBox.ItemTemplate>
</sdk:AutoCompleteBox>
I would like to have a similar code in C# or one that helps me to show the attribute "designacao" in my AutoComleteBox list,