1
votes

I get:

System.Windows.Data Error: 40 : BindingExpression path error: 'State' property not found on 'object' ''PointNetObject' (HashCode=9270846)'. BindingExpression:Path=State; DataItem='PointNetObject' (HashCode=9270846); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')

for one column. All the rows are added to table, but for each row i get the error. Two other columns are displayed just fine for each row. But not the State. Naturally the converter is never called.

Set-up described below.

I have an object:

public class PointNetObject : NetObject
{
    SwitchObjectState State
    {
        get { return _state; }
        set { _state = value; }
    }
}

which inherits class that has properties like Phase and Label

In ViewModel:

public ObservableCollection<PointNetObject> SelectedSwitchItems { get; private set; }

public SelectedObjectsViewModel(SelectedObjects selectedObjects)
{
    SelectedSwitchItems = new ObservableCollection<PointNetObject>(GetSwitches());
}    


IEnumerable<PointNetObject> GetSwitches()
{
    foreach (var netObject in SelectedObjectsInstance.GetSelectedObjectItems(x => IsSwitch(x)))
    {
        yield return (PointNetObject) netObject;
    }
}

in View:

 <DataGrid Name="SelectedSwitchesGrid" CanUserAddRows="False" CanUserResizeColumns="True" CanUserSortColumns="True" IsReadOnly="True" 
                   ItemsSource="{Binding SelectedSwitchItems}"
           <DataGrid.Columns>
                    <DataGridTextColumn Header="{DynamicResource XpStrLabel}" Binding="{Binding Label}" />
                    <DataGridTextColumn Header="{DynamicResource XpStrPhase}" Binding="{Binding Phase}" />
                    <DataGridTextColumn  Header="{DynamicResource XpStrState}" Binding="{Binding State, Converter={StaticResource SwitchObjectStateToStringConverter}}" />
                </DataGrid.Columns>
  </DataGrid>
1
well your SwitchObjectState State property isn't public, which is, like, pretty important.Jonesopolis
thanks, I'm an idiotchar m
@Jonesopolis: Care to write as an asnwer so I can accept it?char m

1 Answers

0
votes

In your model:

public class PointNetObject : NetObject
{
    SwitchObjectState State
    {
       get { return _state; }
       set { _state = value; }
    }
}

You State property isn't declared as public.

Any properties you are binding to from the ViewModel to the View need to be public, or the View won't be able to see it.

Don't worry, we've all done it once.