I'm working on a WPF
application with telerik controls.
I'm using RadListBox
which is bind to the collection. When i select each RadListBoxItem
a detailed view of the BindedItem will be shown in the nearby panel. Only one RadListBoxItem
can be selected at a time.
In the below logic i'm making the following functionality,
- Edit
- Switch to new
- Alert for Save or Discard
- Save/Discard
- Load the selected
Now the issue is When the alert is thrown for Save/Discard, if i click save then the save process is initiated but before the save completed the load is also running in another thread. I have to check if the save is complete and start the load process.
//XAML Code:
<telerik:RadListBox x:Name="lstMarketSeries" ItemsSource="{Binding SCollection, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, NotifyOnSourceUpdated=True, ValidatesOnDataErrors=True}" SelectedItem="{Binding SelectedMSeries, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" telerik:StyleManager.Theme="Windows8">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding LoadSelected}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</telerik:RadListBox>
//ViewModel:
public ICommand LoadSelected { get { return new RelayCommand(LoadSelectedSDetails); } }
/// <summary>
/// Load selected series
/// </summary>
private async void LoadSelectedSDetails()
{
if (SCollection != null)
{
if (!IsChanged())
{
bw = new BackgroundWorker();
bw.RunWorkerAsync();
bw.DoWork += (s, e) =>
{
//Loading functionality here( Have to check if the save is complete)
};
bw.RunWorkerCompleted += (s, e) =>
{
IsBusy = false;
};
}
else
{
await PutTaskDelay(); // This delay is to wait for save to complete
LoadSelectedSDetails();
}
/// <summary>
/// Check if collection is changed
/// </summary>
private bool IsChanged()
{
bool IsChanged = false;
if (SCollection != null)
IsChanged = SCollection.Where(x => x.IsChanged || x.IsNew).Count() > 0;
if (IsChanged)
{
if (ShowMessages.SaveOrDiscardBox())
{
SaveAllDetails(); // Saving runs in a separate thread.
}
else
{
//Discard functionality goes here
}
}
return IsChanged;
}
Kindly help on this issue.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…