0

なぜこれが機能するのかわかりません (単一の 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<> は必要ありません。ところで、何がうまくいかないのかを理解したいのですが...

4

1 に答える 1

0

単一のエンティティにバインドする場合は、CurrentItemの代わりに使用する必要がありItemsSourceます。

于 2012-01-16T19:15:28.720 に答える