I am trying to iterate the combobox items and it is always null.
Here is what I'm trying to accomplish:
foreach (ComboBoxItem Item in ListEditor.ComboBox.Items) { Item.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); if (Item.DesiredSize.Width > Width) Width = Item.DesiredSize.Width; }
ListEditor.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));ListEditor.Width = ListEditor.DesiredSize.Width + Width;
As you are using the ItemsSource property, the items will not be ComboBoxItems. They will be if you add them manually in the Items collection.
The foreach will throw an exception as the item cannot be caster correctly. It is probably a string or whatever the ChecklistFieldlistnameValue generic type collection is.
Here is my block of code:
XamComboEditor ListEditor = new XamComboEditor();ListEditor.Padding = new Thickness(0);ListEditor.HorizontalAlignment = HorizontalAlignment.Left;ListEditor.SelectedItemChanged += new RoutedPropertyChangedEventHandler<object>(ListEditor_SelectedItemChanged);
ListEditor.DisplayMemberPath = "Description";ListEditor.ValuePath = "StatusValue";ListEditor.ItemsSource = fieldInfo.ChecklistFieldListName.ChecklistFieldListNameValue;
EBL.ChecklistFieldValue FieldValue = fieldInfo.ChecklistFieldValue.Where(c => c.TravelerChecklist.Id == _TravelerChecklistId).FirstOrDefault();
Binding MyBinding = new Binding("FieldValue");MyBinding.Source = FieldValue;MyBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;ListEditor.SetBinding(XamComboEditor.ValueProperty, MyBinding);
ListEditor.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); ListEditor.Width = ListEditor.DesiredSize.Width + Width;
Grid.SetColumn(ListEditor, 1);gridControls.Children.Add(ListEditor);
I am seeing what you are trying to do, but I am not seeing how you have bound the XamComboEditor. Can you please give us that code?
If you look at the code in the op you see that I trying to determine what the width of the combo needs to be based on the items in the drop down.
The ComboBox will not be null only when the editor is in edit mode, as the XamcomboEditor uses a comboBox when it is not in edit mode. if you execute this code when the editor is not in edit mode, then it would be null. You can access these items through the ItemsProvider or ItemsSource properties of the XamComboEditor