Hello,
I need some advice about RadAutoCompleteBox.
When I click on RadAutoCompleteBox I want to see all possible results and then I will have a option to choose whether I want to select from them or start searching by typing. Searching for text and then selecting works fine, but unfortunately searching with nothing in it doesn't work. When I click on RadAutoCompleteBox all the results are displayed, but I can't select anything from them until I type something. The hover selection works fine, I just can't select anything if RadAutoCompleteBox.SearchText is empty. Could you help me how to solve this? Thank you very much.
I am sending part of my the source code and example (WpfApp1.zip) where it also not working.
...
<controls:RadAutoCompleteBoxFilter x:Key="RadAutoCompleteBoxFilter" />
...
<telerik:RadAutoCompleteBox Grid.Row="0"
x:Name="CaseAutoCompleteBox"
WatermarkContent="{x:Static rs:ResourceText.Start_Typing}"
ItemsSource="{Binding Suggestions}"
SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
TextSearchMode="Contains"
TextSearchPath="Name"
DisplayMemberPath="Name"
AutoCompleteMode="SuggestAppend"
DropDownItemTemplate="{StaticResource CasesSearchAutoComplete}"
SelectionMode="Single"
SelectionChanged="CaseAutoCompleteBoxSelectionChanged"
PreviewMouseLeftButtonDown="OnPreviewMouseLeftButtonDown"
GotFocus="CaseAutoCompleteBox_OnGotFocus"
FilteringBehavior="{StaticResource RadAutoCompleteBoxFilter}"
/>
public partial class AddMediaToCase
{
public AddMediaToCase()
{
InitializeComponent();
RadWindowInteropHelper.SetShowInTaskbar(this, true);
}
private void CaseAutoCompleteBoxSelectionChanged(object sender, SelectionChangedEventArgs e)
{
var autoCompleteBox = sender as RadAutoCompleteBox;
CaseInformationStackPanel.Visibility = autoCompleteBox.SelectedItem != null ? Visibility.Visible : Visibility.Collapsed;
}
private void OnPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (string.IsNullOrWhiteSpace(CaseAutoCompleteBox.SearchText))
{
CaseAutoCompleteBox.Populate(" ");
}
}
private void CaseAutoCompleteBox_OnGotFocus(object sender, RoutedEventArgs e)
{
if (string.IsNullOrWhiteSpace(CaseAutoCompleteBox.SearchText))
{
CaseAutoCompleteBox.Populate(" ");
}
}
}
public class RadAutoCompleteBoxFilter : FilteringBehavior
{
public override IEnumerable<object> FindMatchingItems(string searchText, IList items,
IEnumerable<object> escapedItems, string textSearchPath,
TextSearchMode textSearchMode)
{
var result =
base.FindMatchingItems(searchText, items, escapedItems, textSearchPath, textSearchMode) as
IEnumerable<object>;
if (string.IsNullOrEmpty(searchText) || !result.Any())
{
return ((IEnumerable<object>)items).Where(x => !escapedItems.Contains(x));
}
return result;
}
}