How to determine whether a property defined in View Model is bound to any control in UI?

StackOverflow https://stackoverflow.com/questions/23527432

  •  17-07-2023
  •  | 
  •  

سؤال

Is there a way to determine whether a property defined in View Model is bound to any controls in View, basically using Visual Studio.

هل كانت مفيدة؟

المحلول

You can double-click on the property name to highlight it. Then hit CTRL+SHIFT+F and select "Entire Solution" to see all occurrences. And from there it's a process of manual inspection.

Alternatively, you can right click the property and select "Find usages", and begin the manual inspection from that point. If you have ReSharper, you can access the advanced menu, which includes dynamic usages.

There are additional ways, but these are run-time. The binding engine itself doesn't know until run-time, that's the beauty of binding.

نصائح أخرى

With help of Garry Vass, I found how we can search for the usage of a property solution-wide. Great help.

Inside Visual Studio -> Right Click on a property - > Find Usages Advanced(CTRL + SHIFT + ALT + F12) - > Search Properties - > Late-Bound references -> Find

The only option you have is "Find in file"

Since binding is done at runtime, the binding references are resolved by using (usually) Microsoft .NET Framework reflection. There is no validation done at compile time or with intellisense.

As such there is no way for the IDE to know what data context of the bound control would be, so impossible to find the references to it.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top