locked
How to display Icon in the ToolBar menu on UWP using markup extension RRS feed

  • Question

  • User385762 posted

    Hi, I am using markup extension developed by ( @NMackay ) to display images on android and uwp platform. Everything works fine in xaml, however now I need to display icon in toolbar in UWP app (which is working fine in Android). I need to know how can I refer this extension in my code C# code.

          var toolbarItem = new ToolbarItem
          {
            Text = "ABC",
            Order = ToolbarItemOrder.Primary,
            Icon = "search.png", **//How to refer extension to display this icon**
            Command = viewModel.MysearchCommand
          };
    

    I am copy & pasting the extension here, since right now I cant post the links in this forum.

    public class PlatformImageExtension : IMarkupExtension<string>
    {
    
        public string SourceImage { get; set; }
    
        public string ProvideValue(IServiceProvider serviceProvider)
        {
            if (SourceImage == null)
                return null;
    
            string imagePath;
            switch (Device.RuntimePlatform)
            {
                case Device.Android:
                    imagePath = SourceImage;
                    break;
                case Device.iOS:
                    imagePath = SourceImage + ".png";
                    break;
                case Device.WinPhone:
                    imagePath = "Images/" + SourceImage + ".png";
                    break;
                case Device.Windows:
                    imagePath = "Images/" + SourceImage + ".png";
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
            return imagePath;
        }
    
        object IMarkupExtension.ProvideValue(IServiceProvider serviceProvider)
        {
            return ProvideValue(serviceProvider);
        }
    }
    
    Tuesday, July 16, 2019 9:25 AM

Answers

  • User76049 posted

    Create a helper class that does the same thing and strip out the markup extension stuff.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, July 16, 2019 9:44 AM