Hi John,
Simply and dumb question?
Have you tried in your OnMouseDown() handler to call this.Focus()?
I have done soimething fairly similar and it works fine, a
previously non-focusable control can grab focus this way...
Also, you might need to change the KeyboadNavigation.TabNavigation
and KeyboardNavigation.DirectionalNavigation attached properties in
order to allow keyboard to pass focus to your canvas when cycling with
tab or navigating with arrows...
John Dunn wrote:
> I'm having trouble with getting my Canvas to grab focus. In the constructor
> of my view that derives from Canvas I'm setting
>
> Focusable=true
>
> but OnGotFocus never gets called. My app also has a treeview in it and it
> doesn't show that it's lost focus when clicking on the viewer ( by changing
> it's hilight color from dark to light gray ). I also tried the following
>
> FrameworkElement::FocusableProperty->OverrideMetadata( Type::GetType(
> "view_t" ), gcnew FrameworkPropertyMetadata( true ));
>
> which I found mentioned somewhere - but it had no effect either. Which is
> fine since I'm not sure what the above does anyways. The canvas does receive
> mouse messages ( OnMouse* ) which I am calling the base class Canvas handers.
> I've also removed all OnMouse* overrides which didn't fix the problem either.
>
> If it's not obvious this is all being written in C++/CLI.
>
> Thanks-
>
> John