I have a Combobox with an item source to an ObservableCollection
listSites = new ObservableCollection<SiteData>()
{
new SiteData("Site 1", true, "HomeAutomation", "Green"),
new SiteData("Site 2", true, "HomeAutomation", "Green"),
new SiteData("Site 3", true, "HomeAutomation", "Green"),
new SiteData("Site 4", false, "HomeAlert", "Red"),
new SiteData("Site 5", true, "HomeAutomation", "Green"),
new SiteData("Site 6", true, "HomeAutomation", "Green"),
new SiteData("Site 7", true, "HomeAutomation", "Green"),
new SiteData("Site 8", false, "HomeAlert", "Red"),
new SiteData("Site 9", true, "HomeAutomation", "Green"),
new SiteData("Site 10", false, "HomeAlert", "Red"),
};
cbxSites.ItemsSource = listSites;
The Combobox also has an ItemTemplate to a StaticResource:
<ComboBox x:Name="cbxSites" VerticalAlignment="Top" Width="250" Margin="0,
0, 0, 0" BorderBrush="White"
ItemsSource="{Binding listSites}" ItemTemplate="
{StaticResource SiteComboBoxItemTemplate}"
HorizontalContentAlignment="Center"
SelectionChanged="CbxSites_SelectionChanged"
IsEditable="True" />
<DataTemplate x:Key="SiteComboBoxItemTemplate">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
<materialDesign:PackIcon Kind="{Binding StatusIcon}"
Width="30" Height="30" Foreground="{Binding StatusColour}"
VerticalAlignment="Center" HorizontalAlignment="Right" />
<TextBlock Text="{Binding SiteName}" Margin="20, 0, 0, 0" />
</StackPanel>
</DataTemplate>
When IsEditable on the ComboBox is set to false, the binding works and I can click on the Combobox and see all the names (Site 1, Site 2, Site 3 etc) and by clicking on an item, it populates that same name in the Combobox as you would expect. When IsEditable is true, the drop down list of the Combobox still displays the site names correctly (Site 1, Site 2, Site 3 etc) but when I select one, instead of the same name of that site populating in the Combobox, I see "CipClient.SiteData" instead. Why is this and how can I fix it?