我正在使用Telerik控件工作WPF
应用程序,使用MVVM
模式。命令在对象绑定之前触发WPF
功能:
我使用它在运行时根据记录数产生telerik:RadListBox
。所以,如果我在我的收藏中有10条记录,则会在应用程序中显示10 RadListBox
。当我选择每个RadListBox
时,SelectedItem
的详细视图(相关值)将显示在附近的面板中。一次只能选择一个RadListBox
。
场景:
因此,选择RadListBox
和编辑面板中的相关信息,当我切换到另一个RadListBox
警报(是/否)将被抛出后,“你要保存的细节?”。我已经在每个对象中实现了INPC
,我会检查它是否被更改。
// XAML:
<telerik:RadListBox x:Name="lstSeries" BorderThickness="1" BorderBrush="#FFCBD8E8" ItemsSource="{Binding SCollection, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, NotifyOnSourceUpdated=True, ValidatesOnDataErrors=True}" ItemTemplate="{StaticResource ImageDataTemplate}" DragEnter="lstMarketSeries_DragEnter" DragLeave="lstMarketSeries_DragLeave" Style="{StaticResource myListboxStyle}" SelectedItem="{Binding SelectedSeries, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" telerik:StyleManager.Theme="Windows8" PreviewKeyDown="RadListBox_PreviewKeyDown" MouseDoubleClick="lstMarketSeries_MouseDoubleClick" PreviewMouseDown="RadListBox_PreviewMouseLeftButtonDown" SelectionChanged="SeriesCommit_SelectionChanged">
</telerik:RadListBox>
//重点对象:
SelectedItem="{Binding SelectedSeries, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
//视图模型:
/// <summary>
/// Get or set selected series.
/// </summary>
public SeriesBO SelectedSeries
{
get { return this.m_SelectedSeries; }
set
{
if (this.m_SelectedSeries != value)
{
this.m_SelectedSeries = value;
OnPropertyChanged();
}
}
}
//Method called once a RadListBox is selected
private void LoadSelectedMarketSeriesDetails()
{
if (!IsChanged())
{
//If there is no object edited then it should load the new selected object
}
}
private bool IsChanged()
{
bool IsChanged = false;
if (SeriesImageList != null)
IsChanged = IsChanged || SeriesImageList.Where(x => x.IsChanged || x.IsNew).Count() > 0;
if (NoteList != null)
IsChanged = IsChanged || NoteList.Where(x => x.IsChanged || x.IsNew).Count() > 0 || IsChanged;
if (IsChanged)
{
if (ShowMessages.SaveMessageBox())
{
//Hitting Yes in alert should save the values.
//When retrieving the SelectedSeries object it shows the recent object selected but i need the last selected one.
}
else
{
//Discard function
}
}
//After a successfull save or discard false is returned
return false;
}
现在的问题是,编辑系列和之后切换时警报(是/否)被抛出。然后我点击保存,但第二个对象被选中并被绑定在SelectedSeries
对象中。当我尝试保存编辑的最后一个对象时,我无法获得这些值。
我需要一些Command
在SelectedSeries
对象获得绑定之前触发。因此,我可以检查属性是否已更改,并且必须限制对象绑定到所选的第二个值。一旦保存完成之前的值,则SelectedSeries
必须绑定到该对象。
预期结果:
一旦第一个选定的系列被编辑并切换到下一个,提醒应甩和警报的结果,该系列应该得到保存或丢弃,它应该移动到下一个系列这是选中的。
保存期间,它的工作良好。但是由于“SelectedSeries”对象绑定到具有最新选择的UI,所以Selected panel系列细节仍显示在面板中。 – iamCR
@SanthoshKumar请告诉我预期的结果是什么? – Ilan
更新了问题 – iamCR