0

我不明白为什么会这样(将单个 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<> 因为我想获得一个实体。而且,顺便说一句,我想了解出了什么问题...

4

1 回答 1

0

当绑定到单个实体时,您应该使用CurrentItem而不是ItemsSource.

于 2012-01-16T19:15:28.720 回答