Skip to main content

Microsoft Silverlight

Unanswered Question Focus Issue After Calling WCF ServiceRSS Feed

(0)

prolay
prolay

Member

Member

0 points

2 Posts

Focus Issue After Calling WCF Service

Hello All,

I am new to this forum and this is my first post. I am working with silverlight for couple of months. I am facing some problems which i would like to share with all of you.

Problem:

Lets say I have three TextBoxes and I make a WCF service call on the KeyDown event ("Tab") of the first text box. Since the service call is asynchronous the UI is not frozen and the user can move anywhere in the screen which will disturb the validation process. So I have Blocked the UI by using a "Popup" so the user does not get the freedom of doing anything. After I get the response from the server If the validation returns "true" I want to focus the next control in the Page.

Now the problem is when I show the "Popup" to block UI the focus changes and I loose trace of what the current control is. The control is a "Custom Control" that is derived from "TextBox" and the KeyDown EventHandler is present inside the "Custom Control".

For Now from the "Custom Control" I am finding the parent's children and then finding among them the control which has got the next TabIndex and then focusing on that Control which i think is lot of processing.

Please give your suggestions on this.

With Regards,

Prolay

varshavmane
varshavmane

Contributor

Contributor

6723 points

1,580 Posts

Re: Focus Issue After Calling WCF Service

Did you try using DispatcherTimer?

Please "Mark as Answer" if this post answered your question. :)
Visit my Blog: http://varshavmane.blogspot.com/

Mog Liang - MSFT
Mog Lian...

All-Star

All-Star

15894 points

1,541 Posts

Re: Focus Issue After Calling WCF Service

Hi Prolay,

Before displaying Block UI, use FocusManager to keep current control's reference. After async call complete, set focus on it

FocusManager.GetFocusedElement();

Thanks,

Mog Liang
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.

prolay
prolay

Member

Member

0 points

2 Posts

Re: Focus Issue After Calling WCF Service

I think the FocusManager do not fit in well here. Actually i think i am unable to explain the problem properly. Let me try again.

I have made a custom control that extends from TextBox

   public class FText : TextBox
    {

    ........

Now the functionality of this control is that when i enter something in the FText control it goes to the server and find out whether the entered value is there in the database or not. If the result is "true" the focus should go to the next control in the UI and if the result is "false" the current control should be focused.

Now before making a server call i block the UI by showing a popup and when the call completes, the first thing that is done is to remove the popup and then if the result is "false" the focus should be stopped at the current control which is a easy task.

 this.Focus();

But if the result is "true" it should go to the next control which i think is a difficult task to attain.

Currently I know two ways it can be attained.

1. Find this control's parent which in most of the cases will be a Canvas/Grid/StackPanel. then parse through those controls and find out which is the control with the next TabIndex and then focus on that particular control. This is the approach that we are using currently.

2. Exposing a attribute which can give the name of the next control.

 public string NextControl { get; set; }

  and then applying this code to focus the required control

 FrameworkElement container = VisualTreeHelper.GetParent(this) as FrameworkElement;
 Control tb = container.FindName(NextControl) as Control;
 tb.Focus();

This approach forces the position of the control i.e if the position of the control changes the "NextControl" will have to configured accordingly.

What is the best approach or is there any other method to handle such situation.

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities