Nimgoble / WPFTextBoxAutoComplete

An attached behavior for WPF's TextBox control that provides auto-completion suggestions from a given collection
https://www.nuget.org/packages/WPFTextBoxAutoComplete/
MIT License
100 stars 37 forks source link

Static in autocomplete code. #10

Closed Quade369 closed 7 years ago

Quade369 commented 7 years ago

I was just wondering if the statics defined in the autocomplete code.

` private static TextChangedEventHandler onTextChanged = ...

private static KeyEventHandler onKeyDown = ...

private static bool _isSubscribed = false;`

Are an issue if I want to use more than one instance of the control on a single application.

Nimgoble commented 7 years ago

Um....Good question. The event handlers shouldn't be a problem, since those are using the sender. "_isSubscribed" might have to be mapped to individual controls...

Quade369 commented 7 years ago

Typically, I'd have given each of them their own attached property to try to ensure it's thread safe. I mean you probably don't want to use the same keyeventhandler for each instance. In my case I'd probably want one handler per VM.

I guess the answer then is "not sure" so I'm wondering if I should switch them to attachedproperties to be safe?

Nimgoble commented 7 years ago

Hey Quade, sorry for the delayed response. I don't know that thread safety really matters with the KeyEventHandler, because it's using the sender each time. So, it's always targeting the correct control.

You could try it your way and let me know how it works out?