FilteringBehavior

6 posts, 1 answers
  1. Matthias Bibo
    Matthias Bibo avatar
    72 posts
    Member since:
    Mar 2010

    Posted 16 Sep 2013 Link to this post


    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
  2. Vladi
    Admin
    Vladi avatar
    744 posts

    Posted 19 Sep 2013 Link to this post

    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 >>
  3. DevCraft banner
  4. Matthias Bibo
    Matthias Bibo avatar
    72 posts
    Member since:
    Mar 2010

    Posted 19 Sep 2013 Link to this post


    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

  5. Vladi
    Admin
    Vladi avatar
    744 posts

    Posted 20 Sep 2013 Link to this post

    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 >>
  6. Matthias Bibo
    Matthias Bibo avatar
    72 posts
    Member since:
    Mar 2010

    Posted 25 Sep 2013 Link to this post

    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
  7. Answer
    Vladi
    Admin
    Vladi avatar
    744 posts

    Posted 25 Sep 2013 Link to this post

    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 >>
Back to Top
DevCraft banner