From ecebb672e64855ff22399e5e208e960316148a35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Wagenf=C3=BChr?= Date: Tue, 20 Aug 2019 13:54:59 +0200 Subject: [PATCH] Restrict "AutoCompleteField" to only on "AutoCompleteManager" In some rare cases it may happen, that the "Loaded" Event of the "TextBox" will be called twice. Because an "AutoCompleteManager" will be added to the "TextBox" each time the "Loaded" Event is fired, it may be added multiple times, resulting in having more than one "AutoCompleteManager". Which results in displaying multiple popups, when the User writes something. --- NZazu/Fields/NZazuAutocompleteField.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/NZazu/Fields/NZazuAutocompleteField.cs b/NZazu/Fields/NZazuAutocompleteField.cs index fe30359..69f1c90 100644 --- a/NZazu/Fields/NZazuAutocompleteField.cs +++ b/NZazu/Fields/NZazuAutocompleteField.cs @@ -12,6 +12,7 @@ namespace NZazu.Fields internal class NZazuAutocompleteField : NZazuField { private readonly IProvideSuggestions _suggester; + private bool _suggesterAttached; public NZazuAutocompleteField(FieldDefinition definition, Func serviceLocatorFunc) : base(definition, serviceLocatorFunc) @@ -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; @@ -59,4 +66,4 @@ private void AttachSuggestor(object sender) manager.AttachTextBox(tb); } } -} \ No newline at end of file +}