Forum Xamarin Xamarin.Forms

How can I refresh a content page without having to reload or use refreshing?

ABloxityABloxity Member ✭✭✭

How can I refresh a content page without having to reload or use refreshing?

I am making a clone of a social network, and so in every action I do, I have to use the refresh to update the app's content.

Answers

  • LandLuLandLu Member, Xamarin Team Xamurai

    There's no such a refreshing Api.
    We need to implement it by ourselves. Create a configuration method to add new controls on Content Page. Clear the content of the content page and call the configuration method to reverse your page to the original state.

  • ABloxityABloxity Member ✭✭✭

    will you have an example?

  • LandLuLandLu Member, Xamarin Team Xamurai
    public MainPage()
    {
        InitializeComponent();
        init();
    }
    
    void init()
    {
        Label label = new Label { Text = "Welcome to Xamarin.Forms!" };
    
        Entry entry = new Entry();
    
        Button btn = new Button();
        btn.Text = "Refresh";
        btn.Clicked += (sender, e) =>
        {
            Content = null;
            init();
        };
    
        var layout = new StackLayout
        {
            Children =
            {
                label,
                entry,
                btn
            }
        };
    
        Content = layout;
    }
    

    Call init method in the constructor to add the controls. And the click event of button implements how to refresh the page.

Sign In or Register to comment.