Articles in this section
Category / Section

How to get toolbar item and change icon using name in SfImageEditor?

By default, In SfImageEditor we can get toolbar items based on index value. We can also get toolbar items using name.

 

Step 1: Create SfImageEditor sample with all necessary assemblies.


Please refer the below link to create a simple SfImageEditor sample along with the ways to configure it.

https://help.syncfusion.com/xamarin/sfimageeditor/getting-started

 

Step 2: To get toolbar item’s you can use available toolbar item’s name in SfImageEditor.

 

Please refer the below link to get available toolbar item’s name in SfImageEditor.

 

https://help.syncfusion.com/xamarin/sfimageeditor/toolbarcustomization#name

 

Code Snippet:

 

private void Toolitem_Clicked(object sender, EventArgs e)
{
    ItemName = GetName.Text;
    ToolbarItem = editor.ToolbarSettings.ToolbarItems;
    var toolbarItem = GetToolItem(ToolbarItem);
    if (toolbarItem != null)
    {
        toolbarItem.Icon = ImageSource.FromResource("ImageEditor_GettingStarted.icon.png");
    }
}

 

private ImageEditor.ToolbarItem GetToolItem(ObservableCollection<ImageEditor.ToolbarItem> toolbarItem)
{
    foreach (var toolItem in toolbarItem)
    {
        if (ItemName != null)
        {
            if (toolItem.Name.ToLower().Equals(ItemName.ToLower()))
            {
                ImageEditorToolbarItem = toolItem;
                break;
            }
            else if (toolItem is ImageEditor.FooterToolbarItem)
            {
                var subitems = (toolItem as ImageEditor.FooterToolbarItem).SubItems.Count;
                if (subitems > 0)
                {
                    var toolabrItem = (toolItem as ImageEditor.FooterToolbarItem).SubItems;
                    GetToolItem(toolabrItem);
                }
            }
        }
    }
    return ImageEditorToolbarItem;
}

 

Sample link:

 

https://www.syncfusion.com/downloads/support/directtrac/general/ze/ImageEditor_GettingStarted1051249361.zip

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied