View.HasDefaultFocus isn't working

Mar 3, 2014 at 6:48 PM
I tried setting View.HasDefaultFocus on various elements, but it isn't doing anything, well at least
not for text boxes because the cursor isn't getting into the text box.

Another question not related: How do you appropriately set short cuts for ViewActions
which aren't added to the actions collection but rather bound to in via normal bindings.

Thank you,

Regards
Coordinator
Mar 5, 2014 at 5:27 AM
Which theme are you using where the focus isn't set?

If you want to use shortcut keys, you can simply add input bindings to any WPF element (usually the root of your view) and bind it to the action you are interested in.


Markus
Mar 5, 2014 at 6:31 AM
MarkusEgger wrote:
Which theme are you using where the focus isn't set?

If you want to use shortcut keys, you can simply add input bindings to any WPF element (usually the root of your view) and bind it to the action you are interested in.


Markus
I am using the Vapor theme, but I have tried this on Metro and Workplace as well, it is not working as well because the writing cursor isn't going into the TextBox
when the view is loaded.

As for the input bindings, I tried that already and it works but the problem is that this requires the control which will be the target of the key binding
to be focused or selected, otherwise it isn't capturing the short cut, but I guess this is a WPF issue rather than a CODE framework one, although I would
be very happy if you could provide a work around.

One last thing Markus, what about the other question I asked you about, and you said you take a look to see what's wrong ?

Thank you,

Greatest regards
Coordinator
Mar 5, 2014 at 2:50 PM
OK, I will take a look at that as well. (I have a whole backlog of items from various customers which I am all trying to go through... yours are in there and raising to the top).

If you set a key binding at the root of the view, it should take in the entire view, shouldn't it?


Markus
Mar 5, 2014 at 9:49 PM
I am setting the key binding at the root of the view, yet it doesn't seem to take effect unless the given button which the action is bound too
is focused.

Anyway thanks for the great job, keep on handling those backlogs :)

Best regards
Coordinator
Mar 18, 2014 at 8:18 AM
So I just tried this on a view:
<mvvm:View xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
           xmlns:mvvm="clr-namespace:CODE.Framework.Wpf.Mvvm;assembly=CODE.Framework.Wpf.Mvvm"
           Style="{DynamicResource EditorLayoutStyle}" Title="Editor">
    <mvvm:View.InputBindings>
        <KeyBinding Key="A" Modifiers="Alt" Command="{Binding TestAction}" />
    </mvvm:View.InputBindings>
    
    <TextBox mvvm:View.HasDefaultFocus="True" />
    ...
This moves the initial focus to the textbox correctly for me.

It also triggers the TestAction when I hit ALT+A.

So I am not sure why this isn't working for you. I tried it with different themes too, and it seems to work fine. Maybe if you still see this same problem, you could create a small repro scenario/sample app for me to take a look at.


Markus
Marked as answer by abnajjar on 3/20/2014 at 4:36 AM
Mar 20, 2014 at 12:38 PM
I tried to write another demo, but thinks worked out OK!.

I couldn't replicate the issue with the first application as I don't know exactly what is causing it.

Anyway, thank your for your support.

Regards