Silverlight 5 + AutoCompleteBox = Error

Just installed SL5 and a set of tools that were released a few days ago.
The error occurs when you set the Text property of AutoCompleteBox to string.Empty. This causes the AutoCompleteBox to malfunction. To reproduce the error:

add an AutoCompleteBox and a button to the home page. Register for TextChanged and Click events. This is the code:

public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); } private void button1_Click(object sender, RoutedEventArgs e) { auto.Text = string.Empty; } private void auto_TextChanged(object sender, RoutedEventArgs e) { // Put a break point here. } } 

At runtime:

1) enter “aa” in the auto box.

2) press the button.

3) enter "q". (TextChanged is still being called).

4) delete "q" - TextChanged is not called.

5) enter "q" again - TextChanged is not called.

6) etc., until you select a new letter. And then it begins.

+4
source share
1 answer

I found a workaround for this weird behavior. You need a control derived from AutoCompleteBox and overriding the OnApplyTemplate method to find the AutoCompleteBox inner text block.

When an internal TextBox TextChanged event occurs, you need to manually trigger the TextChanged event to automatically control the car computer.

 public class CustomAutoComplete : AutoCompleteBox { TextBox mytext; public override void OnApplyTemplate() { base.OnApplyTemplate(); mytext = GetTemplateChild("Text") as TextBox; mytext.TextChanged += new System.Windows.Controls.TextChangedEventHandler(mytext_TextChanged); } void mytext_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e) { this.Text = mytext.Text; OnTextChanged(new RoutedEventArgs()); } } 
+6
source

Source: https://habr.com/ru/post/1386095/


All Articles