You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Stream GetIcon(string iconName)
{
if (string.IsNullOrWhiteSpace(iconName)) return null;
if (Icons.ContainsKey(iconName))
return Icons[iconName];
else
{
var bytes = UILayer.Properties.Resources.reply; // <--- this is a test image in SVG format
Stream stream = new MemoryStream(bytes) {
Position = 0
};
Icons.Add(iconName, stream);
return stream;
}
}`
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello:
I created a custom menu item using the following code, but it cannot display SVG format vector icons (bitmap icons can be displayed normally). I carefully read the development documentation, which clearly indicates that SVG format images can be used.
did I make a mistake somewhere?
doc:
https://learn.microsoft.com/en-us/dotnet/api/microsoft.web.webview2.core.corewebview2contextmenuitem.icon?view=webview2-dotnet-1.0.2194-prerelease#microsoft-web-webview2-core-corewebview2contextmenuitem-icon
`private void CoreWebView2_ContextMenuRequested(object sender, CoreWebView2ContextMenuRequestedEventArgs e)
{
e.MenuItems.Clear();
if (e.ContextMenuTarget.HasSelection && !string.IsNullOrEmpty(e.ContextMenuTarget.SelectionText.Trim('\n')))
{
var item = webViewer.CoreWebView2.Environment.CreateContextMenuItem("Copy Text", GetIcon(iconName), CoreWebView2ContextMenuItemKind.Command);
e.MenuItems.Add(item);
}
}
Stream GetIcon(string iconName)
{
if (string.IsNullOrWhiteSpace(iconName)) return null;
if (Icons.ContainsKey(iconName))
return Icons[iconName];
else
{
var bytes = UILayer.Properties.Resources.reply; // <--- this is a test image in SVG format
Stream stream = new MemoryStream(bytes) {
Position = 0
};
Icons.Add(iconName, stream);
return stream;
}
}`
Beta Was this translation helpful? Give feedback.
All reactions