Can I have a composite shape as a resource in WinRT XAML?

若如初见. 提交于 2020-01-14 03:13:12

问题


I'm developing a Windows 8 Metro-style application and I want to use vector images. As there seems to be no direct support for svg images, I am trying to use a xaml fragment consisting of multiple shapes (a path and some lines) as an image. I would like to have a resource dictionary entry with the composite shape and be able to include it in different pages. Ideally, I would also like to be able to resolve a specific composite shape from a data bound property.

From what I've read, the WPF approach was to have a VisualBrush or DrawingBrush consisting of the shapes, but there are no such classes in Windows 8 (and it seems like it's not even possible to derive from Brush).

How am I supposed to do this using WinRT UI?


回答1:


No, you cannot use a DrawingBrush as the value of a background property in WinRT XAML. It's too bad, huh? Seems like a very powerful features to setup the fill of an object with vector layouts. In fact DrawingBrush is not even part of Windows 8 yet. It is what it is. For now, images are a fine solution. But we feel your pain.

I might as well toss in that VisualBrush is not part of WinRT-XAML either.




回答2:


Each XAML fragment is really a UI element. I think the simplest approach would be to put the XAML into it's own user control and then add the user control to each page you wanted to display the "drawing" on. If you want the user control to display different shapes, you can expose a property on the control, data bind to that property, and inside the setter of the property read the value and toggle the visibility of the various XAML shapes to show or hide whatever parts of the composite image you want. It is a bit brute force, but will do what you want.




回答3:


Windows8 way to have vector graphics in it is just to use ViewBox+Canvas and Path elements. It works well in my opinion, though I do miss VisualBrush.



来源:https://stackoverflow.com/questions/11915561/can-i-have-a-composite-shape-as-a-resource-in-winrt-xaml

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