views:

302

answers:

2

When trying to use the following

EventManager.RegisterClassHandler(typeof(TextBox),
TextBox.GotFocusEvent,
new RoutedEventHandler(TextBox_GotFocus));

I am getting an error on 2nd parameter: "'System.Windows.Controls.TextBox' does not contain a definition for 'GotFocusEvent'"

Any help how to resolve this?

I am in the process of adding "Select All" behaviour for all TextBox in my silverlight app and by having this at Application_Startup in App.xaml.cs I thought would do the trick.

Thanks in advance.

A: 

TextBox doesn't define the static member GotFocusEvent but UIElement does.

Try replacing TextBox with UIElement like so:

EventManager.RegisterClassHandler(typeof(TextBox),
UIElement.GotFocusEvent,
new RoutedEventHandler(TextBox_GotFocus));
Arc
Hi Arc, I tried you suggestion to change it to UIElement, and it is still the same error [UIElement does not contain a definition for'GotFocusEvent'] Any other suggestions?
VoodooChild
in Silverlight 2, we can't declare a routed event. What am I suppose to do to solve the problem described above (regarding select all)? thanks
VoodooChild
A: 

I can't find an EventManager class in the Silverlight documentation?

I'm fairly sure that Silverlight does not support Class Handlers.

The closest you are going to get is to place a handler for GotFocus on some element that contains these TextBoxes and test the OriginalSource property to see if it is of type TextBox.

AnthonyWJones
You are right, it doesn't.The actual need for me to do this was that so that on GotFocus I could atuoscroll the page into viewing area on the screen. (I was going to write a function for that in TextBox_GotFocus) but I guess thats out of the question now...
VoodooChild
the link below describes how you can add the functionality on the Got_Focus to autoscroll the page:http://betaforums.silverlight.net/forums/p/130813/326335.aspx
VoodooChild
Cool, glad you found a solution, although I wouldn't have used the RootVisual to find the transfom but rather the ScrollViewer itself, that way those magic numbers taking into account header and footer size would not have been needed.
AnthonyWJones
I wasn't clear above, I don't have a solution for this.That link above was the solution I would've used *if I had EventManager to use.I am not sure of another way to capture Got_Focus of all the textboxes in my app.If you know of one or can point me into right direction for this, that would be much appreciated :) thanks!
VoodooChild