Display original icon of ToolBarItem without changing the color

I have a problem with ToolBarItem icon. The icon image color is changing with respect to the tintcolor. Image contains Text with different colors(PFA).
If i didn't set the TintColor than it is taking the image color as default. But i want to display the original image with different colors for particular page.

Tagged:

Answers

  • MANIKANTA_GMANIKANTA_G INMember ✭✭

    If I put the below code in the ViewWillAppear of PageRender, the item.Image will always be null.

    if (NavigationController != null)
    {
    foreach (var item in NavigationController.TopViewController.NavigationItem.RightBarButtonItems)
    {
    if(item.Image!=null)
    {
    item.Image = item.Image.ImageWithRenderingMode(UIKit.UIImageRenderingMode.AlwaysOriginal);
    }
    }
    foreach (var item in NavigationController.TopViewController.NavigationItem.LeftBarButtonItems)
    {
    if(item.Image!=null)
    {
    item.Image = item.Image.ImageWithRenderingMode(UIKit.UIImageRenderingMode.AlwaysOriginal);
    }
    }
    }

  • LandLuLandLu Member, Xamarin Team Xamurai

    You can't use an image property directly for a tool bar item. Try the code below in your page's custom renderer:

    public override void ViewWillAppear(bool animated)
    {
        base.ViewWillAppear(animated);
    
        if (NavigationController != null)
        {
            int i = ((ContentPage)Element).ToolbarItems.Count - 1;
            foreach (var item in NavigationController.TopViewController.NavigationItem.RightBarButtonItems)
            {
                var toolBarItem = ((ContentPage)Element).ToolbarItems[i];
                UIImage img = UIImage.FromBundle(toolBarItem.Icon.File);
                if (img != null)
                {
                    item.Image = img.ImageWithRenderingMode(UIKit.UIImageRenderingMode.AlwaysOriginal);
                }                   
                i--;
            }
        }
    }
    
  • MANIKANTA_GMANIKANTA_G INMember ✭✭

    I got the solution with Assets by creating new Image set.

Sign In or Register to comment.