我有一个View Model,其属性如下所示。两个是普通整数,第三个是另一个视图模型的列表。在构造函数中,我创建了ObservableCollection IterationVMList
private IterationVM CurrentIterationVM;
public ObservableCollection<IterationVM> IterationVMList { get; set; }
private int numberOfIterations
public int NumberOfIterations
{
get
{
return numberOfIterations
}
set
{
if numberOfIterations!= value)
{
numberOfIterations= value;
while (IterationVMList.Count() < value)
{
IterationVM It = new IterationVM();
IterationVMList.Add(It);
}
CurrentIterationVM = IterationVMList[numberOfIterations - 1];
OnPropertyChanged("NumberOfIterations");
OnPropertyChanged("Seed");
}
}
}
public int Seed
{
get
{
return CurrentIterationVM.Seed;
}
set
{
if (CurrentIterationVM.Seed != value)
{
CurrentIterationVM.Seed = value;
OnPropertyChanged("Seed");
}
}
}
在xaml中,我想要的是当用户更改NumberOfIterations时,它应该更改种子。如果不在NumberOfIterations属性中调用OnPropertyChanged(&#34; Seed&#34;),我该怎么做呢。有更好的方法吗?
<xceed:IntegerUpDown Grid.Row="5" Grid.Column="1" Width="100" Margin="5" Text="{Binding NumberOfIterations,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Left" Minimum="1"/>
<xceed:IntegerUpDown Grid.Row="0" Grid.Column="1" Width="100" Margin="5" Text="{Binding Seed, Mode=TwoWay}" HorizontalAlignment="Left" Minimum="1"/>