WindowsStoreApps中Textblock的TextChanged事件

时间:2014-02-12 07:53:48

标签: wpf events windows-8 windows-store-apps textblock

WindowsStoreApps TextChanged内有TextblockTextbox事件或与我WindowsPhone类似的任何内容(在TextCompositionEventHandler中,我使用{{1} }})。 确切的事情,我需要的是每当一个值添加到Textblock时,一个事件应该触发以获取TextBlock中的值(每次添加一个值)。

1 个答案:

答案 0 :(得分:0)

TextBlock不提供用户编辑文本内容,因为它只是一个轻量级的控件来显示文本(在windows存储中,如在windows手机中)。由于其内容只能以编程方式更改,因此不会在更改时引发任何事件。您可以在TextBlock here上查看活动。在Windows应用商店应用中,对用户可编辑文本仍有TextBox控件。这has a TextChanged event

如果您确实需要知道何时更新Text属性,则可以设置对该依赖项属性的绑定。您可以使用更改处理程序创建自己的自定义依赖项属性,该处理程序为您提供通知:

class MyClass {
    public static readonly DependencyProperty MyTextProperty = DependencyProperty.Register("MyText", typeof(MyClass), typeof(string), new PropertyMetadata(null, OnMyTextChanged));

    public static void OnMyTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) {
        // Do something
    }
}

然后你需要在某处绑定属性:

// myObj something of type MyClass
obj.SetBinding(textBlock, new Binding { Source = myObj, Path = new PropertyPath("MyText") });