silverlight   发布时间:2022-05-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Silverlight 5 AutoCompleteBox = Bug大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

刚刚安装了几天前发布的SL5和工具包. 将AutoCompleteBox的Text属性设置为String.Empty时会发生错误.它导致AutoCompleteBox处于错误状态.重现错误: 将AutoCompleteBox和Button添加到主页面.注册TextChanged和Click事件.这是代码隐藏: public partial class MainPage : UserControl
刚刚安装了几天前发布的SL5和工具包. @H_801_19@将AutoCompleteBox的Text属性设置为String.Empty时会发生错误.它导致AutoCompleteBox处于错误状态.重现错误

将AutoCompleteBox和Button添加到主页面.注册TextChanged和Click事件.这是代码隐藏:

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)在autoBox中输入“aa”.

2)单击按钮.

3)键入“q”. (仍调用TextChanged).

4)擦除“q” – 不调用TextChanged.

5)再次输入“q” – 不调用TextChanged.

6)依此类推,直到你选了一封新信.然后它重新开始.

解决方法

发现了这种奇怪行为的解决方法.您需要从AutoCompleteBox派生的控件并重写OnApplyTemplate方法以查找AutoCompleteBox的内部TextBox.

当内部TextBox TextChanged事件触发时,您需要手动触发AutoCompleteBox控件的TextChanged事件.

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 = Bug全部内容,希望文章能够帮你解决Silverlight 5 AutoCompleteBox = Bug所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。