This is a migrated thread and some comments may be shown as answers.

FilteringBehavior

5 Answers 153 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
Matthias Bibo
Top achievements
Rank 1
Matthias Bibo asked on 16 Sep 2013, 12:40 PM

Hi,

I am having a weird behavior of the RadAutoCompleteBox. I have written my own behavior to populate all Items if searchtext is empty:
/// <summary>
/// Behavior um Rechte abzufragen
/// /// </summary>
public class AutoCompleteBehavior : FilteringBehavior
{
    public override IEnumerable<object> FindMatchingItems(string searchText, System.Collections.IList items, IEnumerable<object> escapedItems, string textSearchPath, TextSearchMode textSearchMode)
    {
        IEnumerable<object> matches = base.FindMatchingItems(searchText, items, escapedItems, textSearchPath, textSearchMode);
 
        if (matches.Count() == 0 && string.IsNullOrEmpty(searchText))
        {
            return items as IEnumerable<object>;
        }
        return matches;
    }
}

The DropDownBox only shows after typing a Letter an deleting it again. Here is how i configured the RadAutoCompleteBox:
<telerik:RadAutoCompleteBox FilteringBehavior="{StaticResource AutoCompleteBehavior}" x:Name="txt_targetHpsl"
                                                              Grid.Column="0"
                                                              Grid.Row="0"
                                                              Grid.ColumnSpan="2"
                                                              TextSearchMode="StartsWith"
                                                              ItemsSource="{Binding ContextSelektionsErgebnisse}"
                                                              SearchText="{Binding CurrentSelectionWfStep.TargetHpslDescription, Mode=TwoWay, Converter={StaticResource NullStringConverter}}"
                                                              AutoCompleteMode="Suggest"
                                                              HorizontalAlignment="Stretch"
                                                              VerticalAlignment="Center"
                                                              SelectionMode="Single"
                                                              MinWidth="120"
                                                              Foreground="#396C9C" />

The NullStringConveter just returns string.Empty if value == null, because it causes an Exception to Bind SearchText to a Property containing null.

If I dont use a Custom FilteringBehavior, it works without typing and deleting a letter.

Is something wrong with my behavior?

Best Regards
Matthias

5 Answers, 1 is accepted

Sort by
0
Vladi
Telerik team
answered on 19 Sep 2013, 10:46 AM
Hello,

By design when the RadAutoCompleteBox control gets the focus it does not trigger its filtering mechanism. In order to force the control to trigger its filtering when you initially click inside it you could use the GotFocus event. In that event call the Populate() method of the  control. The next code snippets show the described approach:
  • The custom FilteringBehavior:

public class EmptyTextFilteringBehavior : FilteringBehavior
{
    public override IEnumerable<object> FindMatchingItems(string searchText, System.Collections.IList items, IEnumerable<object> escapedItems, string textSearchPath, TextSearchMode textSearchMode)
    {
        var matches = base.FindMatchingItems(searchText, items, escapedItems, textSearchPath, textSearchMode);
 
        if (!matches.Any() && string.IsNullOrWhiteSpace(searchText))
        {
            return items.OfType<object>().Where(x => !escapedItems.Contains(x));
        }
 
        return matches;
    }
}
  • Declare the control in the xaml:

<telerik:RadAutoCompleteBox x:Name="RadAutoCompleteBox" FilteringBehavior="{StaticResource EmptyTextFilteringBehavior}" ItemsSource="{Binding Items}" GotFocus="RadAutoCompleteBox_GotFocus"/>
  • And in the code behind:

private void RadAutoCompleteBox_GotFocus(object sender, RoutedEventArgs e)
{
    this.RadAutoCompleteBox.Populate(this.RadAutoCompleteBox.SearchText);
}

Hope this is helpful.
Regards,
Vladi
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Matthias Bibo
Top achievements
Rank 1
answered on 19 Sep 2013, 01:12 PM

Hello,

Thanks for your answer.

My problem is not that the DropDownBox doesn’t open on Focus, but that it doesn’t open when a letter has been typed that is definitely in the ItemsSource. The Box only opens after typing a blank and removing it again.

If the SearchText contains for example "Tes" and the ItemsSource contains {"Test1", "Test2", "Test3", ...}. If I Type the t after Tes I would expect the dropdown to open with all Items starting with "Test", but it doesn’t. I have to type a blank after "Tes" and remove it again, then the DropDownBox opens and everything works as expected.

 

Best Regards

Matthias

0
Vladi
Telerik team
answered on 20 Sep 2013, 11:15 AM
Hello,

We are not aware of such issue in the current version of RadAutoCompleteBox. If you are not using the 2013.2 724 version of the control which is listed in the thread info could you try to reproduce the issue with that version?

I recorded a short video for you that shows how the control behaves on our side with that version.

Regards,
Vladi
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Matthias Bibo
Top achievements
Rank 1
answered on 25 Sep 2013, 10:57 AM
Hello,

we have downloaded the latest internal-Build and it seems to be fixed here, i had the previos version I think it was 2013.2.611. We cant use the official new Release because of a bug in the MaskedTextInput boxes (http://www.telerik.com/support/pits.aspx#/public/silverlight/15573).

Do you have a release date for the Q3 Version?

Best Regards
Matthias
0
Accepted
Vladi
Telerik team
answered on 25 Sep 2013, 01:42 PM
Hi,

The new official Q3 2013 release of RadControls should be available in the middle of next month.

Regards,
Vladi
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
AutoCompleteBox
Asked by
Matthias Bibo
Top achievements
Rank 1
Answers by
Vladi
Telerik team
Matthias Bibo
Top achievements
Rank 1
Share this question
or