Reputation: 1321
I'm trying to bind up a property in a datatemplate as follows
<DataTemplate x:Key="NMSString0x10DataTemplate">
<TextBlock Text="{Binding Value.Value}" MouseDown="Stringx10_MouseDown"/>
</DataTemplate>
However it's throwing the error
`BindingExpression path error: 'Value' property not found on 'object' ''NMSString0x10' (HashCode=51713556)'. BindingExpression:Path=Value.Value; DataItem='MBINField' (HashCode=63604780); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')
now i know NMSString0x10 has a property called Value, I know that the MBINField (which is the datacontext here) also has a proprty called Value which holds an instance of NMSString0x10.
in fact, as you can see i have an event tied to codebehind which has the following.
private void Stringx10_MouseDown(object sender, MouseButtonEventArgs e)
{
TextBlock tb = (sender as TextBlock);
MBINField field = (tb.DataContext as MBINField);
libMBIN.Models.Structs.NMSString0x10 c = field.Value as libMBIN.Models.Structs.NMSString0x10;
tb.Text = c.Value;
}
and this works fine!
This is obviously an issue with the binding, but for the life of me i can't work out what is wrong.
EDIT:
Found a way to turn tracing on, and noticed what might be an issue, tho i have no understanding of it i'm afraid
System.Windows.Data Warning: 108 : BindingExpression (hash=28048521): At level 0 - for MBINField.Value found accessor ReflectPropertyDescriptor(Value)
System.Windows.Data Warning: 104 : BindingExpression (hash=28048521): Replace item at level 0 with MBINField (hash=51110099), using accessor ReflectPropertyDescriptor(Value)
System.Windows.Data Warning: 101 : BindingExpression (hash=28048521): GetValue at level 0 from MBINField (hash=51110099) using ReflectPropertyDescriptor(Value): NMSString0x10 (hash=46277382)
System.Windows.Data Warning: 108 : BindingExpression (hash=28048521): At level 1 - for NMSString0x10.Value found accessor <null>
that level 1 - for NMSString0x10.Value found accessor <null>
looks like a possible problem, although i have no idea what it means
EDIT 2:
I've tried writing a value converter as suggested below, unfortunaly for some reason it's never actually used (breakpoints never hit, conversion never happens) I've even tried switching the fieldtype in MBINField to dynamic rather than object without any luck.
To me the code behind proves that the object is set correctly, it must be something to do with the binding conventions failing or something along those lines.
Upvotes: 0
Views: 155
Reputation: 628
I wanted to write this to a comment, but I don't have enough rep. Not sure, whether it helps:
What makes me think this:
If this assumption is correct, a possible solution would be to replace the type of MBINField.Value with a base class, that has a property Value, and make NMSString0x10 inherit it. An other solution would be to write a value converter, like this
Upvotes: 1