How to Focus on a TextBlock in XAML WPF with keyboard (for example with tab) in a Grid view?

49 views Asked by At

I have a textblock which has a binding path with a converter, but I am unable to operate that with tab button. Textblock has an Onclick property which opens another page. I want to open that screen with keyboard. Kindly help!

I tried Keyboard Focusable in and also Focusable=On but its not working

1

There are 1 answers

1
mm8 On

You could (should!) use a Button and make it look like a TextBlock:

<Button Click="Button_Click">
    <Button.Template>
        <ControlTemplate TargetType="Button">
            <TextBlock Text="Focus me!" />
        </ControlTemplate>
    </Button.Template>
</Button>

The above element can be both keyboard focused and clicked and still looks like a TextBlock.

Remember that WPF controls are lookless which means that a control's behavior is independent from its appearance.