问题描述
刚装SL5和工具包,被释放前几天。结果
当您将AutoCompleteBox到的String.Empty的Text属性的错误发生。它使AutoCompleteBox是一个越野车的状态。要重现错误:
Just installed SL5 and the toolkit, that were released few days ago.
The bug happens when you set the Text property of the AutoCompleteBox to string.Empty. It causes the AutoCompleteBox to be in a buggy state. To reproduce the bug:
添加一个AutoCompleteBox和一个按钮到主页。注册到框TextChanged和Click事件。这是code-背后:
add an AutoCompleteBox and a Button to the main page. Register to the TextChanged and Click events. This is the code-behind:
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.
}
}
在运行时:
1)型AA到autobox。
1) type "aa" into the autobox.
2)单击按钮。
3)输入Q。 (框TextChanged仍然调用)。
3) type "q". ( TextChanged is still invoked).
4)删除Q - 框TextChanged为不可以调用
4) erase the "q" - TextChanged is not invoked.
5)输入Q再次 - 框TextChanged为不可以调用
5) type "q" again - TextChanged is not invoked.
6),并依此类推,直到你选择一个新的字母。然后,它开始。
6) and so on, until you pick a new letter. And then it's starts over.
推荐答案
我找到了这种奇怪的行为一个解决方法。你需要从AutoCompleteBox和overrride OnApplyTemplate方法得到的控制找到AutoCompleteBox内文本框。
I found a workaround for this strange behavior. You need a control derived from AutoCompleteBox and overrride OnApplyTemplate method to find inner TextBox of AutoCompleteBox.
在内部文本框TextChanged事件触发,你需要手动消防控制AutoCompleteBox的TextChanged事件。
When inner TextBox TextChanged event fires you need to fire TextChanged event of AutoCompleteBox control manually.
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());
}
}
这篇关于Silverlight的5 + AutoCompleteBox =错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!