C
C#16mo ago
r2d25551

❔ How To Refresh ContentPage Controls

When routing from the MainPage to my details page I pass in:
MyData myData = currentSelectedItems.FirstOrDefault() as MyData;
Dictionary<string, object> navParams = new Dictionary<string, object>
{
{ "MyData", myData }
};

await Shell.Current.GoToAsync($"MyDetailsPage", navParams);
MyData myData = currentSelectedItems.FirstOrDefault() as MyData;
Dictionary<string, object> navParams = new Dictionary<string, object>
{
{ "MyData", myData }
};

await Shell.Current.GoToAsync($"MyDetailsPage", navParams);
The detail page properly receives the passed parameter. But there is caveat. It is not available to OnLoaded is called. The initial control values are nearly empty, except for DateTime, etc. Also, there are times when the passed parameters are null, and new detail item is being created. The BindingContext is set in the page constructor, and XAML references the x:DataType:
x:DataType="local:MyData"

public MyData myData;

public MyDetailsPage()
{
InitializeComponent();
BindingContext = this;
}


protected void OnLoaded(object sender, EventArgs e)
{
if (myData == null)
{
isNew = true;
myData = new MyData();
myData.GUID = Guid.NewGuid();
}
}
x:DataType="local:MyData"

public MyData myData;

public MyDetailsPage()
{
InitializeComponent();
BindingContext = this;
}


protected void OnLoaded(object sender, EventArgs e)
{
if (myData == null)
{
isNew = true;
myData = new MyData();
myData.GUID = Guid.NewGuid();
}
}
At this point my controls are blank. How do I ask the page to refresh? Do I need to do so manually for each control?
2 Replies
r2d25551
r2d25551OP16mo ago
protected void OnLoaded(object sender, EventArgs e)
{
if (myData == null)
{
isNew = true;
myData = new MyData();
myData.GUID = Guid.NewGuid();
}

BindingContext = myData;
}
protected void OnLoaded(object sender, EventArgs e)
{
if (myData == null)
{
isNew = true;
myData = new MyData();
myData.GUID = Guid.NewGuid();
}

BindingContext = myData;
}
Accord
Accord16mo ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server