Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Icon Tabbed Page With Badge

$
0
0

Hi, I have found a way to use fa icons in tabbed page and with badges. I have been days figuring this out. I hope it can help someone.
If you have any idea how to improve this please tell me.
I use the plugin Iconize only.

My Tabbed Renderer Page in iOS:
` public class TabbedPageRenderer : IconTabbedPageRenderer
{
protected override void OnElementChanged(Xamarin.Forms.Platform.iOS.VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);

        var base_entry = Element as MyTabbed;

        base_entry.OnDoStuff += (sender2, e2) => DoStuff(base_entry.index);
    }

public void DoStuff(int index)
    {
        var base_entry = Element as MyTabbed;

        var items = TabBar.Items;

        if (base_entry.Badge != "0")
        {
            items[base_entry.index].BadgeValue = base_entry.Badge;
        }
        else
        {
            items[base_entry.index].BadgeValue = null;
        }
    }

`

My Tabbed:

`public class MyTabbed : IconTabbedPage
{

    string badge;
    public EventHandler OnDoStuff;
    public string Badge
    {
        get
        {
            return badge;
        }
        set
        {
            badge = value;
            DoStuff();
        }
    }

    public void DoStuff() 
    {
        if (OnDoStuff != null)
        {
            OnDoStuff(this, new EventArgs());
        }
    }

}`

And an example of the use of My Tabbed:

`public class TabbedOpcoes: MyTabbed
{
public TabbedOpcoes()
{
NavigationPage.SetHasNavigationBar(this, false);

        IconNavigationPage paginaHistorico = new IconNavigationPage(new Historico())
        {
            Icon = "fa-history",
            Title = "HISTORY",
            BarBackgroundColor = (Color)App.Current.Resources["verdeRiopele"],
            BarTextColor = Color.White
        };

        Children.Add(paginaHistorico);

        this.index = 1;
        this.Badge = "2";
    }

`


Viewing all articles
Browse latest Browse all 77050

Trending Articles