I am currently running into some trouble with binding objects to a WPF ListBox. The number of Elements is populated correctly but the Name property cannot be accessed. I get the following error message:
System.Windows.Data Error: 40 : BindingExpression path error: 'Name' property not found on 'object' ''__ComObject' (HashCode=17252513)'. BindingExpression:Path=Name; DataItem='__ComObject' (HashCode=17252513); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')
However, I am able to print this property correctly to the console at runtime.
It looks like the object is not casted correctly
XAML:
<ListBox Name="lbSelectConfiguration" Margin="10" ItemsSource="{Binding Configurations}">
<ListBox.ItemTemplate>
<StackPanel Margin="5" Orientation="Horizontal">
<Image Source="/Resources/Configuration.png" Margin="0,0,8,0" />
<TextBlock Text="{Binding Name}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Code behind
this.DataContext = viewModel;
this.viewModel = viewModel;
foreach (Configuration config in this.viewModel.Configurations)
{
Console.WriteLine(config.Name);
}
Can you help me out? Thank you.