Collapsing SIP when showing overlay

Jun 3, 2011 at 6:04 PM

I have an application where I enter something into a textbox and then click an AppBar button, and the command associated with that shows the progress overlay. What I realized was that when I'm typing into the textbox and then immediately click the AppBar button, the SIP stays open even though the overlay appears. If i click letters on the SIP, the textbox gets updated as well! To fix this, I made the following modifications to the ProgressOverlay source:

1) Added a property called IsVisible - this manipulates the Visibility

2) From the setter of IsVisibile and well as from the Show() method, I call a new method ChangeFocus()

3) New methods:

 private void ChangeFocus()
        {
 
            var parent = FindParent<PhoneApplicationPage>(this);
            if (parent != null)
                parent.Focus();
 
        }
 
        private static T FindParent<T>(UIElement control) where T : UIElement
        {
            UIElement p = VisualTreeHelper.GetParent(control) as UIElement;
            if (p != null)
            {
                if (p is T)
                {
                    return p as T;
                }
                else
                {
                    return FindParent<T>(p);
                }
            }
            return null;
        }

Doing the above makes the SIP disappear when the overlay is shown.

Just thought this might be useful to some of the other folks here...

 

cheers,

Priya

Coordinator
Jun 4, 2011 at 6:40 AM

So I thought about this a bit and I'm actually not going to implment this for a few reasons.  The big one being is I think the end developer should execute the focus in this use case.  If I execute it, it could case a behavior that someone else may not want / expect.  If you're executing Show/Hide, you can easily execute a focus as well to hide the SIP.

Questions I have for you :-):

  1. why create IsVisible as you can set the visibility property on the control if you'd like. 
    1. Doing this seems works just fine Show() { Focus(); /* old code */ }
  2. Why focus the parent instead of the actual control?

Jun 6, 2011 at 2:54 PM
Edited Jun 6, 2011 at 3:23 PM
crutkas wrote:

So I thought about this a bit and I'm actually not going to implment this for a few reasons.  The big one being is I think the end developer should execute the focus in this use case.  If I execute it, it could case a behavior that someone else may not want / expect.  If you're executing Show/Hide, you can easily execute a focus as well to hide the SIP.

Questions I have for you :-):

  1. why create IsVisible as you can set the visibility property on the control if you'd like. 
    1. Doing this seems works just fine Show() { Focus(); /* old code */ }
  2. Why focus the parent instead of the actual control?



You're right in that it should not be a "forced" behavior - my use case is where I always need it to behave this way but otherwise, I think this behaviour must be enabled/disabled via a new property (say, "AutoFocus") on the control. Here's my response to your questions:

1) I'm using MVVM in my application, so I can't invoke the Show/Hide methods from my ViewModel. Before I made these changes, I was binding the Visibility property. However, since I wanted to implement this behaviour, and I can't "override" the Visibility property on the control, I had to introduce a new "IsVisible" property.

2) No real reason - I could set "IsTabStop" to true on the Overlay I guess, and set focus to it - in fact, that might be a better way to do it - as long as the overlay allows me to set "IsTabStop" to True. Thanks for the suggestion!

Hope this makes sense :)