1

Y: The Question

A binding is "merely" a set of name-string pairs which are interpreted at runtime. When this produces unexpected results, can the binding resolution be intercepted? This could reveal issues such as timing problems (improper initialization order, race conditions) and typos, or eliminate them so the debugging focus can be moved.

I'm hoping for a way to intercept the call to Binding.ProvideValue, or similar, but with all the relevant information (Path, DataItem, etc.) available. I want to know how the Binding class understands my instructions, and when.

I tried using an IValueConverter, but it's not called before the error (below) occurs.

I tried writing a MarkupExtension, with a private Binding instance, but it didn't help me out by retrieving the relevant information for free. Specifically, it didn't determine the appropriate DataItem inherited via DataContext. (I'm guessing it acquires the information through internal communications with the containing XAML element, since static code wouldn't be prejudiced against me.)

X: The Problem

I'm working with this binding, which happens to be on an actipro property grid item (and several otherwise identical bindings work just fine):

(edited because I initially copied the wrong binding)

 Value="{Binding VMLeftPLaneOneHoleHoleOneSlugCylinderLen,
                 Mode=OneWay,
                 StringFormat=F3}"

I can't shake the following runtime error. The property exists on the mentioned class, and no spelling error is involved (reasonable guess due to the absurdly long name). It is available publicly (other properties weren't, this is my last one). The property only provides a getter, hence Mode=OneWay.

System.Windows.Data Error: 40 : BindingExpression path error: 'VMLeftPLaneOneHoleHoleOneSlugCylinderLen' property not found on 'object' ''LegacyViewModel' (HashCode=3273904)'. BindingExpression:Path=VMLeftPLaneOneHoleHoleOneSlugCylinderLen; DataItem='LegacyViewModel' (HashCode=3273904); target element is 'PropertyGridPropertyItem' (Name=''); target property is 'Value' (type 'Object')

I've been staring at the code, and I'm in that mood where I'm sure I've checked everything and totally implausible explanations are popping into my head - like the XAML interpreter having a different LegacyViewModel class, one which lacks this specific property. And after typing that I went ahead and hit Clean+Rebuild just to make sure.

I don't have a minimal test case, mostly because this project is gargantuan and unmaintainable in multiple ways. But I'm not asking for a solution to the actual problem, only a technique to help me solve it.

Did I make a blatantly obvious mistake? Is there something I haven't checked? What can I do to measure this fairly deep part of the XAML system?

Community
  • 1
  • 1
Grault
  • 974
  • 12
  • 31
  • 1
    The binding error message you're showing does not match the binding expression, as different property names are involved. Namely `...TwoHoleHole...` vs. `...OneHoleHole...`. Also `...PLane...` with uppercase `L` looks dubious. – Clemens Oct 09 '15 at 12:37
  • Thank you for your second set of eyes... It was the wrong binding, but the correct binding also had `PLane`, and I foolishly didn't have Match Case checked in my Find dialog. If you'd like to take the points for answering, I did ask "Did I make a blatantly obvious mistake?" to hedge my bets. – Grault Oct 09 '15 at 15:44

0 Answers0