I have a xaml
page with label
. I want to update label
after some async task. In my ViewModel constructor
I set default text for my label. And create a async Task
function named SomeTask()
.
Question 1: Where can I call SomeTask()
function. Not able to call async Task
function in constructor
.
Question 2: How can I update Label text after async Task
SomeTask()
function.
public class MyPageViewModel : ViewModelBase
{
private String _selectedText;
public String SelectedText
{
get { return _selectedText; }
set {
if (_selectedText != value)
{
_selectedText = value;
}
}
}
public MyPageViewModel ()
{
_selectedText = "Welcome"; //Default text
}
private async Task<string> SomeTask()
{
return await Task.Run(async () =>
{
await Task.Delay(3000); //Dummy task. It will return the status of Task.
return "Thanks"; //Update Text
});
}
}