I have a WPF application built with MVVM and am trying to display a custom class in a combobox. I am still getting the Namespace.Asset despite overriding the ToString Method to something easier on the eyes. What am I doing wrong?
XAML code
<ComboBox ItemsSource="{Binding Drivers}" SelectedItem="{Binding SelectedDriver}" Grid.Row="20" Grid.Column="1" Grid.ColumnSpan="3"/>
ViewModel Code
public List<Driver> Drivers
{
get
{
return this.drivers;
}
set
{
this.drivers = value;
this.RaisePropertyChanged("Drivers");
}
}
public Driver SelectedDriver
{
get
{
return this.selectedDriver;
}
set
{
this.selectedDriver = value;
this.RaisePropertyChanged("SelectedDriver");
}
}
One of the custom classes code with overriden ToString
public class ExperimentalDriver : Driver
{
public override DriverResponse GetDriverResponse(double time)
{
... random unrelated code....
}
public override string ToString()
{
return "Experimental Driver";
}
}
You might need to set the ToString() on the base class
Something like:
Then your class constructors for your sub classes would simply set the displayName