Hallo Community,
ich möchte meine Combobox mit einer Autovervollständigung ausrüsten.
Die "Suchfunktion" habe ich schon benutzt, allerdings ergab sie keine Treffer.
Hier ist mein Code-Snippet:
MainWindow.xaml:
<ComboBox Height="30" Width="200" IsEditable="True" ItemsSource="{Binding}" IsTextSearchEnabled="False" Name="comboBox">
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel IsVirtualizing="True" IsItemsHost="True" />
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
</ComboBox>
MainWindow.cs:
public MainWindow()
{
InitializeComponent();
List<String> names = new List<string>();
names.Add("Michael");
names.Add("Mike");
names.Add("Manuel");
names.Add("Olaf");
this.DataContext = names;
comboBox.Loaded += delegate
{
TextBox textbox = comboBox.Template.FindName("PART_EditableTextBox", comboBox) as TextBox;
Popup popup = comboBox.Template.FindName("PART_Popup", comboBox) as Popup;
textbox.AutoWordSelection = false;
if (textbox != null)
{
textbox.TextChanged += delegate
{
if (textbox.Text != String.Empty)
{
popup.IsOpen = true;
comboBox.Items.Filter += text =>
{
if (text.ToString().Contains(textbox.Text))
return true;
return false;
};
}
else
{
popup.IsOpen = false;
comboBox.Items.Filter = null;
}
};
}
};
}
Ich habe nun 2 Probleme:
Gibt es eine Möglichkeit, diese automatische Markierung nach einem Zeichen auszustellen?
Könnt ihr mir sagen wie ich dieses zweite TextChanged Event unterbinden kann und wo es her kommt bzw. wer es schmeißt?
Ich würde mich freuen, wenn ihr mir helfen würdet.
Viele Grüße