This question is locked. New answers and comments are not allowed.
I'm binding the ItemsSource of the AutoCompleteBox to a list of a custom object, and keep getting an error when I set the source to my list.
Here's the custom object I'm using:
And when I set the ItemsSource, it throws an InvalidOperationException:
"An exception of type 'System.InvalidOperationException' occurred in Telerik.Universal.UI.Xaml.Input.DLL but was not handled in user codeAdditional information: Failed to compare two elements in the array."
Here's my Xaml:
Thanks,
Joshua
Here's the custom object I'm using:
class
MyObject : IComparable
{
public
string
Name {
get
;
set
; }
public
string
EmailAddress {
get
;
set
; }
public
SolidColorBrush Color {
get
;
set
; }
public
string
FullString {
get
;
set
; }
public
MyObject(
string
name,
string
emailAddress, SolidColorBrush color)
{
Name = name;
EmailAddress = emailAddress;
Color = color;
FullString =
string
.Format(
"{0} <{1}>"
, Name, EmailAddress);
}
public
override
bool
Equals(
object
obj)
{
if
(obj.GetType() !=
typeof
(MyObject))
{
return
false
;
}
MyObject obj2 = obj
as
MyObject;
if
(
this
.FullString == obj2.FullString)
{
return
true
;
}
return
false
;
}
public
int
CompareTo(
object
obj)
{
if
(obj.GetType() !=
typeof
(MyObject))
{
return
0;
}
MyObject obj2 = obj
as
MyObject;
if
(
this
.FullString == obj2.FullString)
{
return
1;
}
return
0;
}
}
And when I set the ItemsSource, it throws an InvalidOperationException:
"An exception of type 'System.InvalidOperationException' occurred in Telerik.Universal.UI.Xaml.Input.DLL but was not handled in user codeAdditional information: Failed to compare two elements in the array."
Here's my Xaml:
<
telerik:RadAutoCompleteBox
x:Name
=
"textBox"
FilterMemberPath
=
"FullString"
VerticalAlignment
=
"Top"
Margin
=
"10,20"
FilterMode
=
"Contains"
DisplayMemberPath
=
"FullString"
>
<
telerik:RadAutoCompleteBox.ItemTemplate
>
<
DataTemplate
>
<
Grid
>
<
Grid.ColumnDefinitions
>
<
ColumnDefinition
Width
=
"35"
/>
<
ColumnDefinition
Width
=
"*"
/>
</
Grid.ColumnDefinitions
>
<
Border
Margin
=
"5"
Background
=
"{Binding Color}"
/>
<
TextBlock
Text
=
"{Binding FullString}"
Grid.Column
=
"1"
VerticalAlignment
=
"Center"
Margin
=
"5"
telerik:RadAutoCompleteBox.IsTextMatchHighlightEnabled
=
"True"
/>
</
Grid
>
</
DataTemplate
>
</
telerik:RadAutoCompleteBox.ItemTemplate
>
</
telerik:RadAutoCompleteBox
>
Thanks,
Joshua