Windows Vista Forums

Focusable Canvas
  1. #1


    =?Utf-8?B?Sm9obiBEdW5u?= Guest

    Focusable Canvas

    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

      My System SpecsSystem Spec

  2. #2


    Marcus Guest

    Re: Focusable Canvas

    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



      My System SpecsSystem Spec

Focusable Canvas problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Canvas does not allow drawing PhredBear Vista General 2 13 Aug 2008
Disposable Canvas? Jon Davis Avalon 26 21 May 2007
Canvas.GetLeft is NaN NetronProject@gmail.com Avalon 1 07 Jun 2006
3D, Canvas, and Databinding Christopher Bennage Avalon 5 31 May 2006
API Standards question: FrameworkElement.Focusable Keith Patrick Avalon 3 27 Feb 2006