ListBox SelectedItem永远不会设置

问题描述 投票:0回答:1

我在数据网格的列中有一个列表框。汽车是可观察集合(BuyersCollection)内的项目列表。

  • 列已填充,但从未设置SelectedCar。
  • 此外,如果我从一行中的一个列表中选择一个项目,然后从另一行中选择一个列表项目,则在网格中选择它们。有没有办法只选择最新的?
<telerik:RadGridView ItemsSource="{Binding BuyersCollection}"   
    <telerik:GridViewDataColumn Header="Cars">
        <telerik:GridViewDataColumn.CellTemplate>
            <DataTemplate>
                <telerik:RadListBox ItemsSource="{Binding Cars}"
                    SelectedItem="{Binding SelectedCar,Mode=TwoWay,Source={StaticResource CarsViewModel}}" DisplayMemberPath="name" SelectionMode="Single">
public Car SelectedCar
{
    get
    {
        return selectedCar;
    }
    set
    {
        if (selectedCar != value)
        {
            selectedCar = value;
            NotifyPropertyChanged(nameof(SelectedCar));
        }
    }
}
wpf xaml data-binding
1个回答
1
投票

检查您的绑定范围是否正确。 SelectedCar上的绑定位于Datatemplate中。这意味着您的买家收藏中的每个“买家”都有一个汽车集合:“汽车”和一个名为“精选汽车”的汽车财产。

© www.soinside.com 2019 - 2024. All rights reserved.