Adding Image on Paths

拥有回忆 提交于 2019-12-31 05:27:16

问题


My problem is I have paths to draw cities and I want to put images inside these cities I cant put Image inside <Path> tags.

Why cant I write such code? any solution?


回答1:


Use a canvas or a custom panel with x,y placements and add images to the correct coordinates (same coordinates used by path).

You can query the path nodes to find their coordinates if you don't know them.

Edit: Since your window size changes and coordinates "stretch" accordingly, you will need to implement a custom panel. - Inherit from Panel and override measure and arrange methods as in this example: http://www.wpftutorial.net/CustomLayoutPanel.html

Your custom panel should have X and Y attached dependency properties (like Canvas does) only that methods should use either relative coordinates (0 to 1) instead of (0 to width and 0 to height) or divide by original path width and height to normalize to coordinates.




回答2:


You can use the Path.Fill for this. Use an ImageBrush.

On a side-note, what can be written as child node/s of a element is determined by the ContentPropertyAttribute, for a ContentControl it points to the Content property for example (as can be seen in the Syntax section of its documentation).



来源:https://stackoverflow.com/questions/9670109/adding-image-on-paths

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!