Closed eduardovedelago closed 4 years ago
`using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; using dotMorten.Xamarin.Forms; using Xamarin.Forms;
namespace teste4 { // Learn more about making custom code visible in the Xamarin.Forms previewer // by visiting https://aka.ms/xamarinforms-previewer [DesignTimeVisible(true)] public partial class MainPage : ContentPage, INotifyPropertyChanged {
public List<string> Users { get; }
public MainPage()
{
InitializeComponent();
this.BindingContext = this;
Users = new List<string>();
Users.Add("Bertuzzi");
Users.Add("Bruna");
Users.Add("Polly");
Users.Add("Rodolfo");
Users.Add("Lester");
}
#region PropertyAutoSuggestBox_TextChanged
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
protected bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
{
if (EqualityComparer<T>.Default.Equals(storage, value))
{
return false;
}
storage = value;
OnPropertyChanged(propertyName);
return true;
}
#endregion
bool isBusy;
public bool IsBusy
{
get => isBusy;
set
{
if (SetProperty(ref isBusy, value))
IsNotBusy = !isBusy;
}
}
bool isNotBusy = true;
public bool IsNotBusy
{
get => isNotBusy;
set
{
if (SetProperty(ref isNotBusy, value))
IsBusy = !isNotBusy;
}
}
private string _pesquisa;
public string Pesquisa
{
get { return _pesquisa; }
set => SetProperty(ref _pesquisa, value);
}
private string _selecionado;
public string Selecionado
{
get { return _selecionado; }
set => SetProperty(ref _selecionado, value);
}
public IEnumerable<string> ObterSugestoes(string text)
{
return Users.Where(x => x.StartsWith(text, StringComparison.InvariantCultureIgnoreCase));
}
//Evento de AutoComplete
private void AutoSuggestBox_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs e)
{
AutoSuggestBox box = (AutoSuggestBox)sender;
if (e.Reason == AutoSuggestionBoxTextChangeReason.UserInput)
{
if (string.IsNullOrWhiteSpace(box.Text))
box.ItemsSource = null;
box.IsSuggestionListOpen = false;
else
{
var suggestions = ObterSugestoes(box.Text);
box.ItemsSource = suggestions.ToList();
}
}
}
//Sugestao Selecionada
private void AutoSuggestBox_SuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs e)
{
var itemselecionado = e.SelectedItem;
Selecionado = $"Item Selecionado: {itemselecionado}";
}
//Evento para pegar se foi utilizada a opçao do usuario ou do auto complete
private void AutoSuggestBox_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs e)
{
if (e.ChosenSuggestion == null)
{
Pesquisa = $"Pesquisa: {e.QueryText} ";
Selecionado = "Item Selecionado: Nenhum";
}
else
Pesquisa = $"Sugestao: {e.ChosenSuggestion}";
}
}
}`
<?xml version="1.0" encoding="utf-8"?>
You'll probably need separate event handlers for each control if you want different behaviors. Or perhaps I'm not understanding right?
Greetings,
This is exactly my problem but i have put the 2 controls in 2 different views.
I'm not really understanding the problem. Why can't you have two different event handlers - one for each control?
I'm not really understanding the problem. Why can't you have two different event handlers - one for each control?
i did in my code and the same issue exists.
The code above both controls uses the same event handlers AutoSuggestBox_TextChanged
, AutoSuggestBox_QuerySubmitted
and AutoSuggestBox_SuggestionChosen
.
The code above both controls uses the same event handlers
AutoSuggestBox_TextChanged
,AutoSuggestBox_QuerySubmitted
andAutoSuggestBox_SuggestionChosen
.
check my code in my issue and you will find the event handlers are different.
I don't see the difference. They both point to the same set of handlers:
<teste4:SuggestBoxCustom
PlaceholderText="Qual o usuario deve aparecer?"
WidthRequest="200"
TextChanged="AutoSuggestBox_TextChanged"
QuerySubmitted="AutoSuggestBox_QuerySubmitted"
SuggestionChosen="AutoSuggestBox_SuggestionChosen"/>
<teste4:SuggestBoxCustom
PlaceholderText="Qual o usuario deve aparecer?"
WidthRequest="200"
TextChanged="AutoSuggestBox_TextChanged"
QuerySubmitted="AutoSuggestBox_QuerySubmitted"
SuggestionChosen="AutoSuggestBox_SuggestionChosen"/>
I don't see the difference. They both point to the same set of handlers:
<teste4:SuggestBoxCustom PlaceholderText="Qual o usuario deve aparecer?" WidthRequest="200" TextChanged="AutoSuggestBox_TextChanged" QuerySubmitted="AutoSuggestBox_QuerySubmitted" SuggestionChosen="AutoSuggestBox_SuggestionChosen"/> <teste4:SuggestBoxCustom PlaceholderText="Qual o usuario deve aparecer?" WidthRequest="200" TextChanged="AutoSuggestBox_TextChanged" QuerySubmitted="AutoSuggestBox_QuerySubmitted" SuggestionChosen="AutoSuggestBox_SuggestionChosen"/>
check here : https://www.dropbox.com/sh/r014a0za2tsnt5x/AACeU4dmlLK2FqplP0e99qgda?dl=0
I tried with different events.
I also tried to change the focus, without success, in the example sent: yes the same event is being used but I tested it with different events without success.
I will try to explain better: if you add two components in the same view. When I type in one of them, the other receives the same values.
Perhaps I'm not understanding what your issue is. You said you just wanted to unlink the events.
Perhaps a simple app that reproduces the issue plus a screen recording of what you're seeing might help
Btw, there's a sample in the sample repo with two controls in the same and that works just fine
Both "AutoSuggestBox_QuerySubmitted" and "AutoSuggestBox_SuggestionChosen" change the same two labels so naturally both controls would do the exact same thing.
this movie with the problema https://youtu.be/8tWnaSpRRas
and project example
Thanks but the video is private so I can't see it
i fix the link https://www.youtube.com/watch?v=8tWnaSpRRas
Thanks! That behavior makes absolutely NO sense. I'll try and debug it a bit tonight. Have you had a chance to debug and figure out where the changes are coming from yet?
I've tried without success
Apparently there is a link between the events or a single instance.
however, by the logic of how the components are instantiated, it really doesn't make any sense.
the change_text event is called multiple times
Figured it out. Fixed in master
thanks
i have a problem i need add two components in view but not working
if add text in one component the other repeat the value added in de first component. this problem occurred if add text programatic or in keyboard
I need to unlink the events