.net WPF extract graphics used in a control
I am trying to get the print button from the Docu开发者_高级运维mentViewer control so that I can use the image for another control.
I know I could just image capture the button with a screen shot and a little editing and use the extracted image as as source.
Using the existing reference image would be far more efficient.
Run Peter Blois' snoop.exe. Use the mouseover feature to get the properties of the control containing the graphic you want, and expand the visual tree in snoop until you spot the actual image you want. Inspect its properties and find the source URI of the image. This will tell you which assembly and resource name you are loading. You can then use the same source URI to extract and save the image yourself (e.g. Like this).
Edit: It's not an image in this case. Using Snoop to get the x:Name of the element, I walked the visual tree until I got the PrintButton, and examined it in the debugger. It is using a DrawingBrush with 19 separate drawings to make the printer icon resolution independent. You can STILL get an exact copy of it though, by using the XamlWriter to save the Button's background (DrawingBrush) and then you can use the DrawingBrush yourself.
精彩评论