我正面临一个小问题。我绑定ComboBox有两个属性。 IDTypeCodes是具有IDTYPDSC和IDTYPCDE属性的集合。 Ome更多的集合是具有IDTYPECDE属性的PCodes。
我想在ComboBox中添加所有IDTYPCDE但是为了显示目的,我正在使用IDTYPDSC。但是SelectedValue将是
当我尝试再次打开wiindow时,应显示IDTYPECDE和此值。
<ns:GridViewDataColumn>
<ns:GridViewDataColumn.CellTemplate>
<DataTemplate>
<ns:ComboBox Margin="8,0"
x:Name = "cmbIDTypeCode"
SelectedValue="{Binding IDTYPECDE,Mode=TwoWay}"
Loaded="cmbIDTypeCode_Loaded" />
</DataTemplate>
</ns:GridViewDataColumn.CellTemplate>
</ns:GridViewDataColumn>
.cs文件============================
private void cmbIDTypeCode_Loaded(object sender, RoutedEventArgs e)
{
cmbIDTypeCode = (NetSolControls.ComboBox)sender;
cmbIDTypeCode.ItemsSource = IDTypeCodes;
cmbIDTypeCode.DisplayMemberPath = "IDTYPDSC";
cmbIDTypeCode.SelectedValuePath = "IDTYPCDE";
}
=============================================== ==========================================
我也试过这个,但问题仍然存在。现在我如何获得cmbIDTypeCode的引用?因为它位于Grid的DataTemplate中。
if(cmbIDTypeCode == null)cmbIDTypeCode = new NetSolControls.ComboBox(); 绑定bindSelectedValue = new Binding(“IDTYPECDE”); bindSelectedValue.Source = Controller.DataContext.PROPOSALAPPLICANT [index] .PROPOSALAPPLICANTIDDETAIL; 绑定bindDisplayMemberPath = new Binding(“IDTYPDSC”); bindDisplayMemberPath.Source = IDTypeCodes; 绑定bindSelectedValuePath = new Binding(“IDTYPCDE”); bindSelectedValuePath.Source = IDTypeCodes; bindDisplayMemberPath.Mode = BindingMode.OneWay; bindSelectedValuePath.Mode = BindingMode.OneWay; bindSelectedValue.Mode = BindingMode.TwoWay; cmbIDTypeCode.SetBinding(NetSolControls.ComboBox.DisplayMemberPathProperty,bindSelectedValue); cmbIDTypeCode.SetBinding(NetSolControls.ComboBox.SelectedValuePathProperty,bindSelectedValuePath); cmbIDTypeCode.SetBinding(NetSolControls.ComboBox.SelectedValueProperty,bindSelectedValue);
=============================================== ==================在另一种方式累了===========================
object wantedNode = gvIDDetail.FindName(“cmbIDTypeCode”);返回null。我也试过这种方式,但仍然没有成功。
ItemsSource ="{Binding IDTypeCodes.IDTYPECODEInfo}"
DisplayMemberPath="IDTYPDSC"
SelectedValuePath="IDTYPCDE"
SelectedValue="{Binding PropsoalApplicants.PROPOSALAPPLICANTIDDETAILInfo.IDTYPECDE, Mode=TwoWay}" />
</DataTemplate>
</ns:GridViewDataColumn.CellTemplate>
</ns:GridViewDataColumn>