开发者

How to bind event in the style in Silverlight 4

I have a control where is about 100 hundred TextBoxes, and I need for each of them have binded event to GotFocus event (where I select all text).

I cant use EventSetter as in WPF, so what do you use to开发者_JAVA技巧 bind event in style?


You'll have to subclass the TextBox class and then use that in all your code.

You can then put the GotFocus event handler in that subclass, otherwise you'd have to add the GotFocus event handler to all your code.

public class MyTextBox : TextBox
{
    protected override void OnGotFocus(RoutedEventArgs e)
    {
        // Add your code in here
        base.OnGotFocus(e);
    }
}

Then in your XAML you'd have:

<my:MyTextBox ..... />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜