问题
When I'm drawing a layout on a webpage, using CSS, there can be dozens of rules, scattered across dozens of files, that could possibly influence how an element is actually displayed. Which is why the DOM explorers are such critical tools - I can select an element on a browser and see exactly what CSS rules are being applied to it.
In WPF, there can again be many rules - styles and templates and inline attributes and settings injected from the code-behind - that could possibly be interacting to determine how a given element is displayed.
Is there a way for me to look at an element, say a ComboBox, and to quickly determine exactly why it is drawing three times as tall as I think it should?
回答1:
- Snoop - The WPF Spy Utility
- Mole - Visualizer With Property Editing
Personally, I use Snoop. I'm not familiar with Mole, but I heard it is "better" (subjective), though it isn't free. There is a trick to working with Snoop though, if you have a window created that isn't the main window, you can target it by doing a Ctrl+Shift+MouseOver (that actually targets the current visual control). This took me awhile to figure out, and knowing that is super useful!
回答2:
One free tool that I use from time to time is Snoop. It's good for simple things but may crash on complex things
回答3:
The position/size layout of WPF visuals is not calculated according to some declarative set of rules in the manner of CSS. WPF layout occurs using imperative code and so it is not possible to know from looking at the starting XAML or the resulting visual tree how it was achieved.
A container control such as the StackPanel uses imperative code to layout the children in the expected stacked manner. Because we happen to know how it will operate it is easy to think this is therefore easy to know in advance. But what if you create a custom control that decides to layout controls in a completely random way? You could never be able to show how the end result was achieved.
来源:https://stackoverflow.com/questions/8596270/is-there-a-wpf-equivalent-to-a-dom-explorer