views:

26

answers:

1

when I try to focus on my "autocompletetextbox" I failed I write autocompletetextbox.focus() but the cursor still focus in another what should I do or write to enable to write in it or focus?

A: 

I experienced the same thing -- it does not work properly in its current form (I expect you're talking about the AutoCompleteBox that comes with the February 2010 release of WPFToolkit).

I created a subclass:

public class AutoCompleteFocusableBox : AutoCompleteBox
{
    public override void OnApplyTemplate()
    {
        base.OnApplyTemplate();
        var textbox = Template.FindName("Text", this) as TextBox;
        if(textbox != null) textbox.Focus();
    }
}

This sets focus to the actual TextBox (called "Text") that is part of the default ControlTemplate.

Jay
where should I put this class I tried at the class which has the auto complete box but it doesn't work ?
salamonti
In your XAML you use this instead of `AutoCompleteBox`. So if you have this class in namespace XYZ, you import that namespace in the root of the XAML file, with an alias like xyz and then use <xyz:AutoCompleteFocusableBox Width="500" x:Name="myFocusBox" …>
Jay
I tried but blend get me an error AutoCompleteFocusableBox doesn't support wpf!!!
salamonti
Are you in fact using the February 2010 WPFToolkit release? What version of Blend? This works for me in Blend 3. With your project loaded in blend, you should be able to find this control using the search feature in the toolbox, and add it through the GUI just like any other control.
Jay
thanks so so so much Jay
salamonti