private static void OnSelectedIndexPropertyChanged(DependencyObject source, DependencyPropertyChangedEventArgs e) { AutoComplete control = source as AutoComplete; if (e.NewValue != null) { try { int index = (int)e.NewValue; if (index == -1) { control.SetValue(SelectedItemProperty, control.MapaObjects["null"]); } else if (control.InternalItemSelected == null || (control.InternalItemSelected != null && index != control.InternalItemSelected.index)) { control.SetValue(SelectedItemProperty, control.GetObjectByIndex(index)); } } catch (Exception ex) { } } }
private static void OnSelectedValuePropertyChanged(DependencyObject source, DependencyPropertyChangedEventArgs e) { AutoComplete control = source as AutoComplete; System.Diagnostics.Debug.WriteLine("OnSelectedValuePropertyChanged: " + control.txt.Text); string codigo = ""; if (e.NewValue == null || (e.NewValue != null && String.IsNullOrEmpty(e.NewValue.ToString()))) { codigo = "null"; } else { codigo = e.NewValue.ToString(); } if (control.MapaObjects.ContainsKey(codigo)) { if (control.InternalItemSelected == null || (control.InternalItemSelected != null && control.GetCodigoObject(control.MapaObjects[codigo]) != control.InternalItemSelected.Codigo) ) { control.SetValue(SelectedItemProperty, control.MapaObjects[codigo]); } } }
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); } }