Skip to content
This repository has been archived by the owner on Feb 20, 2022. It is now read-only.

Prevent Multiple AutoComplete PopUps #103

Merged
merged 2 commits into from
Aug 20, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions NZazu/Fields/NZazuAutocompleteField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace NZazu.Fields
internal class NZazuAutocompleteField : NZazuField<string>
{
private readonly IProvideSuggestions _suggester;
private bool _suggesterAttached;

public NZazuAutocompleteField(FieldDefinition definition, Func<Type, object> serviceLocatorFunc)
: base(definition, serviceLocatorFunc)
Expand All @@ -37,14 +38,20 @@ protected override Control CreateValueControl()

// we have to do this on load because some wpf stuff does not work if no parent is set
// i.e. some popup magic on window
result.Loaded += (sender, args) => { AttachSuggestor(sender); };
result.Loaded += (sender, args) =>
{
if (_suggesterAttached) return;
_suggesterAttached = true;

AttachSuggester(sender);
};

return result;
}

private void AttachSuggestor(object sender)
private void AttachSuggester(object sender)
{
// no suggester, no suggestions ;)
// no suggester, no suggestions ;)
if (_suggester == null) return;

var tb = (TextBox) sender;
Expand All @@ -59,4 +66,4 @@ private void AttachSuggestor(object sender)
manager.AttachTextBox(tb);
}
}
}
}