I've been searching for hours on this error that appears in the output window. I'm pretty new to bindings in WPF, so I'm sure there's something I'm missing.
Full text of the error (there is one for each binding path, all similar to this one):
System.Windows.Data Error: 39 : BindingExpression path error: 'TestItem' property not found on 'object' ''String' (HashCode=-842352750)'. BindingExpression:Path=TestItem; DataItem='String' (HashCode=-842352750); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')
EDIT: Everything seems to work as it should, but I get these errors in the output window.
XAML:
<UserControl>
<UserControl.Resources>
<c:MyData x:Key="myDataSource"/>
<DataTemplate x:Key="image">
<Image x:Name="TheImage" />
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Path=PassFail}" Value="PASS">
<Setter TargetName="TheImage" Property="Source" Value="Images/accept.png" />
</DataTrigger>
<DataTrigger Binding="{Binding Path=PassFail}" Value="FAIL">
<Setter TargetName="TheImage" Property="Source" Value="Images/delete.png" />
</DataTrigger>
<DataTrigger Binding="{Binding Path=PassFail}" Value="WARNING">
<Setter TargetName="TheImage" Property="Source" Value="Images/warning.png" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
<Storyboard x:Key="OnMouseLeftButtonDown1"/>
</UserControl.Resources>
<UserControl.DataContext>
<Binding Source="{StaticResource myDataSource}"/>
</UserControl.DataContext>
<ListView Margin="0,94,-4,-7" x:Name="lsvwOutput" ItemsSource="{Binding Source={StaticResource myDataSource}}" MouseUp="lsvwOutput_MouseUp" FontFamily="Verdana">
<ListView.View>
<GridView>
<GridViewColumn Header="Test Item" Width="300" DisplayMemberBinding="{Binding Path=TestItem}" />
<GridViewColumn Header="Information" Width="0" DisplayMemberBinding="{Binding Path=Information}"/>
<GridViewColumn Header="Result" Width="0" DisplayMemberBinding="{Binding Path=PassFail}"/>
<GridViewColumn Header="Result" CellTemplate="{StaticResource image}" />
</GridView>
</ListView.View>
</ListView
</UserControl>
Code behind:
public class MyData : INotifyPropertyChanged
{
private string _testitem = "";
private string _information = "";
private string _passfail = "";
public string TestItem {
get { return _testitem; }
set
{
_testitem = value;
OnPropertyChanged("TestItem");
}
}
public string Information {
get { return _information; }
set
{
_information = value;
OnPropertyChanged("Information");
}
}
public string PassFail {
get { return _passfail; }
set
{
_passfail = value;
OnPropertyChanged("PassFail");
}
}
public string Text { get; set; }