2

嘿,我有一个包含以下属性的 viewModel:

    private List<Product> _products;

    public List<Product> Products
    {
        get { return _products; }
        set
        {
            _products = value;
            RaisePropertyChanged("Products");
        }
    }

    Product _selectedProduct;

    public Product SelectedProduct
    {
        get { return _selectedProduct; }
        set
        {
            _selectedProduct = value;
            RaisePropertyChanged("SelectedProduct");
        }
    }

在 View Model Constructor 中,我填充它们:

         Products = (List<Product>)item;
         if (Products.Count > 0)
             SelectedProduct = Products[0];

XAML 看起来像:

<ribbon:RibbonComboBox Label="Product"  >
                    <ribbon:RibbonGallery   SelectedItem="{Binding SelectedProduct,  Mode=TwoWay}"  Command="{Binding ParameterChangeCommand}">
                        <ribbon:RibbonGalleryCategory ItemsSource="{Binding Products}"   />
                    </ribbon:RibbonGallery>
                </ribbon:RibbonComboBox>

为什么我的组合框不自动选择第一个项目启动(顺便说一下组合框正确填充了数据)?稍后,如果所选项目发生更改,组合框将正确更新。

4

0 回答 0