1

Closed

CTRL-TAB Focus problem/solution

description

Hi,

I found that the Comic Book Reader suffers the same CTRL-TAB problem that I previously experienced in Edi.
The solution to getting CTRL-TAB to work as expected is to set a default keyboard focus within the document view. One simple solution is to have a textbox and the FocusManager acquire focus on that textbox by default.

Documents usually have no textbox so I found a better solution, which is an attached property (see attachment). You can use it like this in your view:

... UserControl x:Class="Edi.View.StartPage" ...
         Focusable="True"
         KeyboardNavigation.IsTabStop="True"
         Name="StartPageView"
         behav:KeyboardFocus.On="{Binding ElementName=StartPageView}"
Your app is pretty cool by the way so I hope this improves the experience for those who use the keyboard (as I often do...)

file attachments

Closed Mar 8, 2013 at 12:26 PM by TheCamel
Fixed

comments

TheCamel wrote Mar 6, 2013 at 10:02 PM

Thanks for your contribution and very appreciated comments.
I never saw before that Avalon displays a tab+ctrl dialog with documents....:-)
Will include that in the next version
but I am very busy with CBR.WinRT and trying to communicate with...
Thanks

TheCamel wrote Mar 6, 2013 at 10:30 PM

Hi, there is something missing in what you submit...?
KeyboardFocus.On ??

TheCamel wrote Mar 6, 2013 at 10:47 PM

ok, solved, I took the good file from your project
should I do that for all type of document ??

dirkster wrote Mar 6, 2013 at 11:25 PM

Yes I would recommend this for all types of documents. You can also verify this in a codeproject article where I discuss this problem in more depth:

http://www.codeproject.com/Articles/483533/AvalonDock-2-0-Tutorial-Part-2-Adding-a-Start-Page

TheCamel wrote Mar 7, 2013 at 12:53 PM

I manage that way....

public static class VisualHelper
{
    public static void AllowFocus(UIElement element)
    {
        if (!System.ComponentModel.DesignerProperties.GetIsInDesignMode(element))
        {
            element.Focusable = true;
            element.SetValue(KeyboardNavigation.IsTabStopProperty, true);
            element.SetValue(KeyboardFocus.OnProperty, element);
        }
    }
just need to call in view constructors for documents only

VisualHelper.AllowFocus(this);

works for all view types
no need to give name or create controls

Thanks to you...will be published soon

wrote Mar 8, 2013 at 12:26 PM

wrote May 16, 2013 at 12:55 PM