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

Create ToolbarItems, Binding Context and layout dynamically Xamarin forms

$
0
0

I have a tableview which gets generated dynamically. I want to add toolbar items on Mainpage and a label at top, but don't know how to add that to my main Content page, which already takes in tableview object.

Also with that I want to add INotify property change, to bind the UI elements, and that too dynamically.

Following is my sample code:

TableView mainTable = new TableView();
TableRoot root = new TableRoot();

    foreach (var sections in titles)
    {
        var layout = new StackLayout();
        var labels = from s in models
                     where s.Title == sections
                     select s;                

        foreach (var label in labels)
        {
            var forgetPasswordLabel = new Label   // Your Forget Password Label
            {
                Text = label.Lists,
                FontSize = 20,
                TextColor = Color.Blue,
                HorizontalOptions = LayoutOptions.Center,
            };

            var forgetPassword_tap = new TapGestureRecognizer();
            forgetPassword_tap.Tapped += (s, e) =>
            {                        
                DisplayAlert("Tapped", "This is a tapped Span. " + label.Lists, "OK");
            };
            forgetPasswordLabel.GestureRecognizers.Add(forgetPassword_tap);                                        

            layout.Children.Add(forgetPasswordLabel);                                                       
        }
        root.Add(new TableSection(sections)
                {
                    new ViewCell() {View = layout}
                });
    }
    mainTable.Root = root;            
    Content = mainTable;

With the above code I want to dynamically add toolbaritems also on the Page, a Label at the top and notification property event for individual properties. I am getting stuck on how to assign all these elements to my main Content page.

Any help or code suggestions would be great.

Thanks In Advance!!!..


Viewing all articles
Browse latest Browse all 77050

Trending Articles