This question is locked. New answers and comments are not allowed.
Hi,
I'm using the RadAutoCompleteBox to implement a kind of "universal search" box in our application. At the moment, I have two lists;
List<ToDoTask> Tasks
List<Patient> Patients
I want both of these to be searchable, so I have made the classes implement the following common interface:
public interface ISearchable
{
string SearchFilterString { get; }
string SearchDisplayString { get; }
}
And the binding for the RadAutoCompleteBox is:
List<ISearchable> Suggestions
which is a cast and concatenation of the two lists. I have set FilterMemberPath and DisplayMemberPath to the appropriate member names, as below:
<telerik_in:RadAutoCompleteBox FilterMemberPath="SearchFilterString" DisplayMemberPath="SearchDisplayString" FilterMode="Contains" ItemsSource="{Binding Suggestions}" Foreground="{StaticResource ForegroundBrush}" BorderThickness="0,0,0,2" BorderBrush="{StaticResource ForegroundBrush}" HorizontalAlignment="Stretch" Grid.Row="1" Grid.ColumnSpan="2" VerticalAlignment="Top" Margin="70,25,25,0"/>
The control works fine if the source only contains one of the two lists, but if I provide the concatenated lists, I get an InvalidCastException
Unable to cast object of type 'ViewModels.DataViewModels.Patient' to type 'ViewModels.DataViewModels.ToDoTask'."
A screenshot of the call stack is attached.
I don't fully understand why it is trying to cast from one type to the other when the List is of ISearchable and in theory, the comparer shouldn't know what the types are beyond the interface provided. Am I being thick? Could anyone cast some light on this?
I'm using the RadAutoCompleteBox to implement a kind of "universal search" box in our application. At the moment, I have two lists;
List<ToDoTask> Tasks
List<Patient> Patients
I want both of these to be searchable, so I have made the classes implement the following common interface:
public interface ISearchable
{
string SearchFilterString { get; }
string SearchDisplayString { get; }
}
And the binding for the RadAutoCompleteBox is:
List<ISearchable> Suggestions
which is a cast and concatenation of the two lists. I have set FilterMemberPath and DisplayMemberPath to the appropriate member names, as below:
<telerik_in:RadAutoCompleteBox FilterMemberPath="SearchFilterString" DisplayMemberPath="SearchDisplayString" FilterMode="Contains" ItemsSource="{Binding Suggestions}" Foreground="{StaticResource ForegroundBrush}" BorderThickness="0,0,0,2" BorderBrush="{StaticResource ForegroundBrush}" HorizontalAlignment="Stretch" Grid.Row="1" Grid.ColumnSpan="2" VerticalAlignment="Top" Margin="70,25,25,0"/>
The control works fine if the source only contains one of the two lists, but if I provide the concatenated lists, I get an InvalidCastException
Unable to cast object of type 'ViewModels.DataViewModels.Patient' to type 'ViewModels.DataViewModels.ToDoTask'."
A screenshot of the call stack is attached.
I don't fully understand why it is trying to cast from one type to the other when the List is of ISearchable and in theory, the comparer shouldn't know what the types are beyond the interface provided. Am I being thick? Could anyone cast some light on this?