Ok this is a little complex.
Without going into it too much, I'm reflecting over a class to collect it's fields and then adding each field into a class
public class MBINField
{
public string Name { get; set; }
public dynamic Value { get; set; }
public string NMSType { get; set; }
}
I'm then adding all of these to a collection, and binding that collection to a listview itemsource, from there i use a TemplateSelector to display a datatemplate based on the type of object that is stored.
Now my issue comes from when the Value of an MBINField is a class, for some reason I cannot bind to the properties of that class. It throws the follow error:
System.Windows.Data Error: 40 :
BindingExpression path error: 'Name' property not found on 'object' ''GcBaseBuildingPalette' (HashCode=1107452)'.
BindingExpression:Path=Name;
DataItem='GcBaseBuildingPalette' (HashCode=1107452);
target element is 'TextBox' (Name='');
target property is 'Text' (type 'String')
System.Windows.Data Information: 20 :
BindingExpression cannot retrieve value due to missing information.
BindingExpression:Path=Name; DataItem='GcBaseBuildingPalette' (HashCode=1107452);
target element is 'TextBox' (Name='');
target property is 'Text' (type 'String')
System.Windows.Data Information: 21 :
BindingExpression cannot retrieve value from null data item. This could happen when binding is detached or when binding to a Nullable type that has no value.
BindingExpression:Path=Name;
DataItem='GcBaseBuildingPalette' (HashCode=1107452);
target element is 'TextBox' (Name='');
target property is 'Text' (type 'String')
System.Windows.Data Information: 10 :
Cannot retrieve value using the binding and no valid fallback value exists;
using default instead.
BindingExpression:Path=Name; DataItem='GcBaseBuildingPalette' (HashCode=1107452);
target element is 'TextBox' (Name='');
target property is 'Text' (type 'String')
Now, i can confirm through debug that GcBaseBuildingPalette does indeed have a property called Name, and that the datacontext is correct and have a valid GcBaseBuildingPalette object. In fact if i add a onclick event to the textbox and in code
behind set the value, it works without an issue
TextBox tb = (sender as TextBox);
MBINField field = (tb.DataContext as MBINField);
libMBIN.Models.Structs.GcBaseBuildingPalette c = field.Value as libMBIN.Models.Structs.GcBaseBuildingPalette;
tb.Text = c.Name;
this works without any issues, So i cannot for the life of me work out why it wont work, it's also possible of interest that adding a converter to this problem never gets called, breakpoints are never hit in either Convert or ConvertBack.
I'm hoping this is something that is easy to fix!
Ben Murray