我需要在我的datagrid中显示两个组合框列.ItemsSource属性正在填充ProductModel类。
public class ProductModel
{
public int ProductId { get; set; }
public string Code { get; set; }
public string Name { get; set; }
public List<decimal> Prices { get; set; }
public decimal Cost { get; set; }
public decimal Stock { get; set; }
public List<string> Presentations { get; set; }
public string BarCode { get; set; }
}
XAML:
<DataGrid x:Name="dgProducts" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Height="343" Width="351" ItemsSource="{Binding ProductList}" AutoGenerateColumns="False"
SelectedItem="{Binding SelectedProduct}" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseDoubleClick" >
<i:InvokeCommandAction Command="{Binding RowDobuleClickCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
<DataGrid.Columns>
<DataGridTextColumn Header="Descripción" Binding="{Binding Name}" Width="200" />
<DataGridComboBoxColumn Header="Precios" Width="70"/>
<DataGridComboBoxColumn Header="Presentaciónes" Width="70" />
<DataGridTextColumn Header="Disponible" Binding="{Binding Stock}" Width="100" />
</DataGrid.Columns>
</DataGrid>
如何从相同的项目源数据网格或类似的东西绑定属性价格和演示文稿。 ?
答案 0 :(得分:0)
替换下面的代码:
<DataGridComboBoxColumn Header="Precios" Width="70"/>
<DataGridComboBoxColumn Header="Presentaciónes" Width="70" />
使用以下代码:
<DataGridTemplateColumn Header="Precios" Width="100" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding Prices}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Presentaciónes" Width="100" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding Presentations}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>