private static void OnSelectedItemPropertyChanged(DependencyObject source, DependencyPropertyChangedEventArgs e) { AutoComplete control = source as AutoComplete; System.Diagnostics.Debug.WriteLine("OnSelectedItemPropertyChanged: " + control.txt.Text); if (control.MapaObjects.Count == 0) { Item item = new Item() { Codigo = "null", Descricao = SELECIONE }; control.Items.Add(item); control.MapaObjects.Add(item.Codigo, null); control.MapaItems.Add(item.Codigo, item); } else if (control.MapaObjects.ContainsKey(control.GetCodigoObject(e.NewValue))) { control.InternalItemSelected = control.MapaItems[control.GetCodigoObject(e.NewValue)]; if (control.InternalItemSelected != null) { control.SetValue(SelectedValueProperty, control.InternalItemSelected.Codigo); control.SetValue(SelectedIndexProperty, control.InternalItemSelected.index); control._bufferSearch.Clear(); if (!control._ehEntrada) { control.LabelLinkItemSelected = control.SetLabelLink(control.GetDescricaoObject(control.MapaObjects[control.InternalItemSelected.Codigo])); control.txt.Text = control.InternalItemSelected.Descricao; control._bufferSearch.Append(control.InternalItemSelected.Descricao); control.FecharPopup(); } else { control.txt.Text = ""; } control.txtHolder.Text = ""; if (control.SelectionChanged != null) { control.SelectionChanged(control, e); } } } }
private static void OnItemsSourcePropertyChanged(DependencyObject source, DependencyPropertyChangedEventArgs e) { AutoComplete control = source as AutoComplete; System.Diagnostics.Debug.WriteLine("OnItemsSourcePropertyChanged: " + control.txt.Text); IEnumerable <object> lista = (IEnumerable <object>)e.NewValue; if (lista != null && control != null) { // Inicializa os mapas de referência para cada atribuição do source control.MapaObjects = new Dictionary <string, object>(); control.MapaItems = new Dictionary <string, Item>(); control.Items = new List <Item>(); control.InternalItemSelected = null; control.LabelLinkItemSelected = control.SetLabelLink(""); control.ParseToItems(lista); control.MinimumSearchLength = 0; control.SetValue(HasItemsProperty, control.Items.Count() > 1); } }