Silverlight project.
In my View code, I call a method in Model View to get the value.
public MyViewModel ViewModel
{
get
{
if (this.viewModel == null)
this.viewModel = new MyViewModel();
return this.viewModel;
}
set
{
if (this.viewModel != value)
{
this.viewModel = value;
}
}
}
However, an asynchronous callback is not called. Sometimes it is caused by a delay. This way I get the value 1900-01-01 00:00:00.000instead of the correct time.
DateTime value;
public void GetDateTime()
{
var proxy = new WcfClient();
proxy.GetCurrentDateTimeCompleted -= ProxyGetCurrentDateTimeCompleted;
proxy.GetCurrentDateTimeCompleted += ProxyGetCurrentDateTimeCompleted;
proxy.GetCurrentDateTimeAsync();
}
private void ProxyGetCurrentDateTimeCompleted(object sender, GetCurrentDateTimeCompletedEventArgs args)
{
try
{
value = args.Result;
Call the code behind.
this.viewModel.GetDateTime();
Update 1
In the comment, I added a few explanations. The "View" box is checked. If I click on it or cancel it, a window with the Yes / No button will appear. Whatever you choose “Yes” or “No”, I will record the date and time in the event MessageBoxYesNoSelection_Closed. The event method is still in code.
Flag Code Code:
if (clickedCheckBox != null)
{
var msgBoxControl = new MessageBoxControl();
msgBoxControl.Closed -= MessageBoxYesNoSelection_Closed;
msgBoxControl.Closed += MessageBoxYesNoSelection_Closed;
if (clickedCheckBox.IsChecked == true)
{
var curDateTime = this.ViewModel.value;
Inside MessageBoxYesNoSelection_Closedwe get the value.
this.ViewModel.GetDateTime();// WCF async call
this.ViewModel.UpdateValue(value); // another WCF async call, need value from GetDateTime() method return result.
this.ViewModel.UpdateAnotherValue(value, user); // third WCF async call
, , , .