Reputation: 35822
Context
I would like to diagnose a binding problem. Without exposing the problem details here, I decided to put a diagnostic button on my ContentPage, and would like to write a refresh in the most purest stupidest way, just to see, the already bound content shows up this way or not.
Question
So I have my button and its event handler in place, I can not figure out how to call a Refresh or similar?
public partial class MainView : ContentPage
{
public MainView()
{
InitializeComponent();
}
void OnButtonClicked(object sender, EventArgs args)
{
// I would like to refresh this contentpage here:
}
}
Upvotes: 2
Views: 7611
Reputation: 13601
Simplest way would be to use Navigation.PushAsync
, or App.Current.MainPage = new MainView()
to reset the UI.
But if you want to simply re-construct the view, then I guess calling InitializeComponent
should do the trick.
void OnButtonClicked(object sender, EventArgs args)
{
var viewModel = BindingContext;
BindingContext = null;
InitializeComponent();
BindingContext = viewModel;
}
Note: This code only re-constructs the view (not the bound data) - assuming that you don't want to use the navigation or setting the
MainPage
trick - to refresh the UI.
Upvotes: 2