【发布时间】:2015-11-24 02:25:43
【问题描述】:
我的视图中有一个 WPF DataGrid,其中有一列我希望能够使用组合框进行编辑。这样做,我在我的视图模型上创建一个属性,如下所示:
public List<EnumeradorWCFModel> TiposCarga { get; set; }
使用 WCF 服务正确填充属性。现在这是我的 DataGrid 定义:
<DataGrid ItemsSource="{Binding Path=TarifarioSel.TarifariosDet}"
IsReadOnly="False" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridComboBoxColumn Width="200" Header="Tipo Carga" ItemsSource="{Binding Path=TiposCarga}"
SelectedValueBinding="{Binding Path=ID_TipoCarga}" DisplayMemberPath="Descripcion" SelectedValuePath="ID"/>
</DataGrid.Columns>
我也试试这个,没有运气:
<DataGrid ItemsSource="{Binding Path=TarifarioSel.TarifariosDet}"
IsReadOnly="False" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridComboBoxColumn Width="200" Header="Tipo Carga" ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type UserControl}}, Path=DataContext.TiposCarga}"
SelectedValueBinding="{Binding Path=ID_TipoCarga}" DisplayMemberPath="Descripcion" SelectedValuePath="ID"/>
</DataGrid.Columns>
问题是如何将组合框列的 ItemsSource 属性绑定到我的视图模型中的属性。
请帮忙!谢谢!
【问题讨论】:
-
乍一看你的绑定似乎不错,(只有第二个)。您是否尝试过用 ObservableCollection 替换列表,还是在输出中出现绑定错误?
-
谢谢@Esh,自己找。我发布了答案。