To cut a long story short I have a section of my application that contains a series of listboxes bound to an object instance in Xaml. Using an IValueConverter
, I was able to retrieve a list of <Part>
objects from the master object and display the .ToString()
form of the retrieved objects. What I want to do, however, is show the Name
property of the object instead. I set the DisplayMemberPath
to Name
but the result only blanks out the listboxitem
. I've posted the relevant portions of the code below:
XAML:
<Window.Resources>
<local:LocationtoEquipmentCOnverter x:Key="locationEquipmentFiller" />
</Window.Resources>
<Window.DataContext>
<local:MegaWdiget/>
</Window.DataContext>
<ListBox x:Name="listboxFront" HorizontalAlignment="Left" Margin="180,45,0,0" VerticalAlignment="Top" Width="82" Opacity="0.5" ItemsSource="{Binding ConverterParameter=Front, Converter={StaticResource locationEquipmentFiller}, Mode=OneWay}" DisplayMemberPath="Name"/>
The ValueConverter:
public class LocationtoEquipmentCOnverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
MegaWidget MWidget = (MegaWidget)value;
Location loc = MWidget.Locations[(string)parameter];
return loc.Contents;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
The MegaWidget Object contains the following:
[XmlElement]
public Dictionary<string, Location> Locations { get; set; }
The Location Object contains a List that has the actual objects I need to query for their names:
public List<Part> Contents;
Solution Found
After continuing along the line of troubleshooting recommended by Mate, I've found that the objects being passed are Part objects and not ListBoxItems. This has resulted in the ListBox
being filled with the actual objects instead of ListBoxItems. By changing the ValueConverter
to pass a List
of ListBoxItems with the content tag set to what I need, the ListBoxes populate properly. I've listed the solution in the question area below: