-
Notifications
You must be signed in to change notification settings - Fork 686
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PathIconSource claims to support sharing but throws exception (AKA shared Geometry issue) #827
Comments
In response to a suggestion from @be5invis, here is more info on the icon topic. Icons are a very important topic, considering that most apps uses multiple icons in multiple places in multiple kinds of GUI elements (icons in buttons, toolbars, menus, tabs, standalone, etc). Thus it's surprising to observe that, currently, icon rendering hardly works in WinUI/UWP unfortunately. Example 1:Look at a really simple case where you have an instance of Example 2:You have an instance of Example 3:You have an SVG file that you want to use as an icon in multiple places in your app. Again you're out of luck because the SVG renderer contains bugs: See issue #825 |
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 5 days. |
Seems like this is still an issue. Are there currently no way of sharing data for PathIcons? |
This needs to be reopened. It is still a problem. |
A very common requirement is to use the same icon/symbol in multiple different buttons/places within an app. Nearly every non-trivial app needs this ability. The documentation for PathIconSource says this is supported:
It says it can be shared but if you try to share it, ArgumentException (HResult=0x80070057) is thrown. SymbolIconSource shares successfully but not PathIconSource.
Actually the underlying problem is that Geometry fails to share when you use the same Geometry instance with multiple instances of IconSourceElement or PathIcon or Shapes.Path.
In comparison, the older WPF-Desktop does support sharing of Geometry instances provided that you first invoke Geometry.Freeze (Freezable.Freeze). Unfortunately UWP does not support Freeze. (It supports Style.Seal but not Freeze.)
To work around this problem in UWP, we're forced to clone the Geometry instances whenever they're used in multiple places (very wasteful!), but how should that be done? UWP does not support the System.Windows.Media.Geometry.Clone method. For app authors to implement their own version of Clone is no small task because it requires manually copying all properties of all subclasses of Geometry, PathFigure, and all subclasses of PathSegment. Furthermore it's wasteful to have multiple clones of the same icons in RAM. It's also a substantial performance hit because whenever you create a new instance of a Page or UserControl, you must first clone all the icons/Geometry instances that the Page uses.
The problem of cloning Geometry is further worsened by the fact that UWP also lacks support for the "capacity" parameter in the constructor of PointCollection necessary for PolyBezierSegment.Points and other subclasses of PathSegment. The missing "capacity" parameter means that when you clone a PointCollection, the internal data is repeatedly reallocated/resized unnecessarily. This makes cloning even more expensive.
WPF-Desktop also has System.Windows.Media.StreamGeometry which is great for making efficient shared path-based icons, but again this feature is missing in UWP unfortunately.
Expected behavior
The text was updated successfully, but these errors were encountered: