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

Commit

Permalink
Merge pull request #103 from mwagenfuehr/prevent-multiple-popups
Browse files Browse the repository at this point in the history
Prevent Multiple AutoComplete PopUps
htochenhagen authored Aug 20, 2019
2 parents 5f0b656 + ecebb67 commit d83cfbc
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions NZazu/Fields/NZazuAutocompleteField.cs
Original file line number Diff line number Diff line change
@@ -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)
@@ -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);
}
}
}
}

0 comments on commit d83cfbc

Please sign in to comment.