我不明白为什么会这样(将单个 Car 绑定到 RadDataForm):
xml:
<tk:RadDataForm ItemsSource="{Binding Path=Cars}"
AutoGenerateFields="True" DataContext="{Binding}" />
视图模型:
public void OnNavigatedTo(NavigationContext navigationContext)
{
carId = int.Parse(navigationContext.Parameters["IdRecord"]);
Cars= _carContext.GetCarById(carId);
}
private IEnumerable<Car> cars;
public IEnumerable<Car> Cars
{
get { return this.cars; }
set
{
if (this.cars!= value)
{
this.cars= value;
this.RaisePropertyChanged(() => this.Cars);
}
}
}
这不是:
xml:
<tk:RadDataForm CurrentItem="{Binding Path=CurrentCar}"
AutoGenerateFields="True" DataContext="{Binding}" />
视图模型:
public void OnNavigatedTo(NavigationContext navigationContext)
{
carId = int.Parse(navigationContext.Parameters["IdRecord"]);
CurrentCar= _carContext.GetCarById(carId).FirstOrDefault();
}
private Car currentCar;
public Car CurrentCar
{
get { return this.currentCar; }
set
{
if (this.currentCar!= value)
{
this.currentCar= value;
this.RaisePropertyChanged(() => this.CurrentCar);
}
}
}
我不想要 IEnumerable<> 因为我想获得一个实体。而且,顺便说一句,我想了解出了什么问题...