Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I determine where a XAML object property value coming from?

Tags:

wpf

I have a bunch of textblock objects in my program, and the foreground color of all of these is white. I want to find out what causes it to be this way.

Is there any means in Visual Studio of tracing back the origin of a property value, whether by template or containing object?

EDIT: After issuing a bounty, this question got a lot of interesting responses with a variety of proposed approaches. I think there's something there, but so far I have not been able to figure out how to apply any of these more effectively than just trial and error hunting through the code. If anybody wants to take up the charge and advance one of the responses as useful, I'm watching.

like image 958
Alan Baljeu Avatar asked Mar 09 '15 23:03

Alan Baljeu


1 Answers

I tend to use Snoop to poke around the visual tree when I need to understand where bound values are coming from. You can use it to look at your control properties and follow either bindings back to DataContexts or walk up and down the tree to see where a value might be inherited from.

Fire up Snoop, drag the crosshairs over your WPF application (or refresh the process list and select from the dropdown), then position your mouse pointer over your TextBlock control and Ctrl-Shift-LeftClick. Snoop will zoom the visual tree in on your control and allow you to look at or edit your control properties.

like image 60
mcr Avatar answered Oct 20 '22 04:10

mcr