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

Xamarin.forms tabbedPage with enum object in ItemsSource

$
0
0

Hi, I've try to create a simple two tabbed page app with xamarin forms.
This is the code of App.cs:

public class App
{
public static Page GetMainPage ()
{
string[] controlli = { "UNO", "DUE"};
TabbedPage _page = new TabbedPage ();
_page.Title = "Pagina";

        _page.ItemsSource = new oggetto[] {
            new oggetto("uno", controlli),
            new oggetto("due", controlli)
        };

        _page.ItemTemplate = new DataTemplate(() => {
            return new basePage();
        });

        return _page;
    }
}

This the code of oggetto.cs:

public class oggetto
{
public string nome { private set; get; }
public string[] controlli { private set; get; }

    public oggetto (string _nome, string[] _controlli)
    {
        this.nome = _nome;
        this.controlli = _controlli;
    }

    public override string ToString()
    {
        return nome;
    }

}

and this of baseBase.cs:

public class basePage : ContentPage
{
public basePage ()
{
var _self = this;

        _self.SetBinding (ContentPage.TitleProperty, "nome");

        Button _lblDue = new Button {};
        _lblDue.SetBinding (Button.TextProperty, "controlli");
        _lblDue.Clicked += (object sender, EventArgs e) => {
            var _ppp = _self.GetValue(ContentPage.TitleProperty);
        };

        StackLayout _content = new StackLayout{
            HorizontalOptions = LayoutOptions.Center,
            VerticalOptions = LayoutOptions.CenterAndExpand,
            Children = {
                _lblDue,
            }
        };
       _self.Content = _content;
    }
}

I've try to replace the string[] controlli in oggetto.cs with enum (that it was my 1* try):

public enum controls {
label,
button,
check
}

And string[] controlli = { "UNO", "DUE"}; in App.cs with:

oggetto.controls controlli = new oggetto.controls {
oggetto.controls.button,
oggetto.controls.label,
oggetto.controls.label
};

But I cannot understand how I can retrive the value of this object in basePage.cs :(

Can someone help me please?

Thanks very much!


Viewing all articles
Browse latest Browse all 58056

Trending Articles