我无法理解为什么这样做(将单个Car绑定到RadDataForm):
XAML:
<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);
}
}
}
而不:
XAML:
<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&lt;&gt;因为我想得到一个单一的实体。 顺便说一下,我想了解出了什么问题......
答案 0 :(得分:0)
绑定到单个实体时,您应使用CurrentItem
而不是ItemsSource
。