扩展TextBox会引发RPC_E_WRONG_THREAD异常

时间:2018-03-10 02:49:43

标签: xaml uwp uwp-xaml

我正在创建一个DelayedTextbox。我这样做是通过扩展TextBox并添加依赖属性(感谢另一个问题的帮助)

所以我有一个cs文件,如下所示:

public class DelayedTextBox : TextBox
{
   public int Delay
    {
        get
        {
            return (int)GetValue(DelayProperty);
        }
        set
        {
            SetValue(DelayProperty, value);
        }
    }

    public static readonly DependencyProperty DelayProperty =
        DependencyProperty.Register(
            "Delay",
            typeof(int),
            typeof(DelayedTextBox),
            new PropertyMetadata(300));
}

然后在我的xaml文件中,我尝试使用新控件:

<h:DelayedTextBox Delay="300" />

其中Delay是依赖属性之一。

当我运行代码时,第一次DelayedTextBox.cs尝试访问Delay时会抛出以下错误:

  

System.Exception:&#39;应用程序调用了为&gt;不同线程编组的接口。 (HRESULT异常:0x8001010E(RPC_E_WRONG_THREAD))&#39;

如何使用自定义控件正确扩展文本框?

0 个答案:

没有答案
相关问题