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

  • Question

  • User388968 posted

    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.

    Monday, January 13, 2020 7:17 PM

All replies

  • User369979 posted

    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.

    Tuesday, January 14, 2020 6:43 AM
  • User388968 posted

    @LandLu will you have an example?

    Tuesday, January 14, 2020 5:02 PM
  • User369979 posted
    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.

    Wednesday, January 15, 2020 9:46 AM