嘿,我有一个包含这些属性的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>
为什么我的ComboBox没有自动选择第一个Itemon启动(顺便说一下,组合框是否正确填充了数据)?稍后,如果更改了所选项目,则会正确更新组合框。