문제

In WindowsStoreApps is there a TextChanged Event for Textblock or any thing similar as we have for Textbox (In WindowsPhone,I used TextCompositionEventHandler). The Exact thing, I need is whenever a value is added to the Textblock an event should fire to get the values in the TextBlock(each time a value is added).

도움이 되었습니까?

해결책

TextBlock does not provide for user editing of text content, as it is just a lightweight control to display text (in windows store as in windows phone). Since its content can only be changed programmatically, there will be no event raised on change. You can see the events on TextBlock here. In Windows Store apps there is also still a TextBox control for user-editable text. This has a TextChanged event.

If you really need to know when the Text property is updated, you can set up a binding to that dependency property. You can create your own custom dependency property with change handler which provides you notification:

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
    }
}

Then you need to bind the property somewhere:

// myObj something of type MyClass
obj.SetBinding(textBlock, new Binding { Source = myObj, Path = new PropertyPath("MyText") });
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top