Blake Simmons
Blake Simmons

Reputation: 466

How can I replace the SearchBar icon in a Xamarin.Forms custom renderer for GTK?

I am working on a Xamarin project that includes a build for GTK. I am attempting to create a custom renderer for many of the Controls, but am having trouble finding, accessing and changing the properties for the control. For example, I would like to replace the "magnifying glass" icon for the SearchBar control with something more similar to the default icon on the Android platform.

I've created the custom renderer:

namespace MyProject.GTK.CustomRenderers
{
    public class CustomSearchBarRenderer : Xamarin.Forms.Platform.GTK.Renderers.SearchBarRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<SearchBar> e)
        {
            base.OnElementChanged(e);
            var searchBar = Control;
            // How do I replace the image?
        }
    }
}

but from there I am at a loss as there are practically no resources on custom renderers for GTK. I've tried looking at the GTK.Renderers.SearchBarRenderer to see if the class its derived from contains any useful properties or methods, as well as trying to find something meaningful in the GTK documentation and the repository for the Xamarin.Forms.GTK package, to no avail. I'm just not really sure how to understand the inner workings of the controls in this build so I can't figure out what I should even be looking for. Any pointers or resources for this or any GTK specific custom renderer work would be much appreciated.

Upvotes: 1

Views: 437

Answers (1)

Morse
Morse

Reputation: 9134

You can check Xamarin Forms GTK

SearchBar is implmented by the use of element called SearchEntry which uses ImageButton and the icon is set by below code

_searchButton.ImageWidget.Pixbuf = RenderIcon("gtk-find", IconSize.SmallToolbar, null); // Search icon

Refer

This should help you begin modifying, if you can get access to SearchEntry in your custom renderer you can change icon, otherwise you will have to create your own search bar, which takes lot of effort.

Upvotes: 1

Related Questions