I have a question regarding XamDataGrid, and a XamComboEditor in an unboundfield. The XamDataGrid is acting as a type of shopping cart. It is bound to an ObservableCollection of LineItemViewModels (Property is VmCatLineItems). One of the properties of a line item is that it contains an ObservableCollection of AllowableShipMethods (different line items may have different ship methods). I am trying to get that collection of ship methods to bind to the XamComboEditor in the unboundfield, but have been unsuccessful. I would appreciate any suggestions.
XamDataGrid Info:
<igWpf:XamDataGrid x:Name="DgCart2" KeyUp="DgCart2_OnKeyUpDeleteItem" TabIndex="3" ActiveDataItem="{Binding VmCartLineItems}" DataSource="{Binding VmCartLineItems, Mode=TwoWay, NotifyOnSourceUpdated=True, UpdateSourceTrigger=PropertyChanged}" RecordsDeleted="DgCart2_OnRecordsDeleted" CellUpdated="UpdateTotal" IsSynchronizedWithCurrentItem="True" Theme="Aero" Width="932" Canvas.Top="50" Margin="0,15,0,0" Height="390" >
UnboundField Info:
<!--Ship Method Field-->
<igWpf:UnboundField Height="30" Width="86" x:Name="ShipMethod" Label="Ship Method">
<igWpf:UnboundField.Settings>
<igWpf:FieldSettings EditorType="{x:Type igEditors:XamComboEditor}">
<igWpf:FieldSettings.EditorStyle>
<Style TargetType="{x:Type igEditors:XamComboEditor}">
<Setter Property="ItemsSource" Value="{Binding VmCartLineItems.Items[0].AllowableShipMethods}"/>
<Setter Property="DisplayMemberPath" Value="ShippingName" />
<Setter Property="ValuePath" Value="ShippingCode" />
<Setter Property="SelectedIndex" Value="0"/>
<Setter Property="VerticalContentAlignment" Value="Stretch"/>
<EventSetter Event="SelectedItemChanged" Handler="OnShipMethodChanged"></EventSetter>
</Style>
</igWpf:FieldSettings.EditorStyle>
</igWpf:FieldSettings>
</igWpf:UnboundField.Settings>
</igWpf:UnboundField>
Property Contained in OrderEntryViewlModel the XamDataGrid is bound to:
public ObservableCollection<LineItemsViewModel> VmCartLineItems
{
get { return _vmItems; }
set
_vmItems = value;
RaisePropertyChanged("VmCartLineItems");
}
That property contains within it the following, which is what I am trying to bind in the ship method field:
public ObservableCollection<ShippingMethods> AllowableShipMethods
get
return this.allowableShipMethods;
if (this.allowableShipMethods != value)
this.allowableShipMethods = value;
this.RaisePropertyChanged("AllowableShipMethods");
Hello Lloyd,
I have been looking through your post and created a sample project based on the provided code snippet. I have bound the ItemsSource property of the XamComboEditor to the DataItem.AllowableShipMethods collection. Then the user can choose between the items of this collection using the ComboEditor.
Please have a look at the attached project and let me know if it helps you in resolving your issue.
Thanks you, Maria, for your prompt response. However, your solution doesn't quite work. I realize that one piece I left out is that this grid is inside a user control. That user control has its datacontext set to a OrderEntryViewModel, which contains the LineItemViewModel, in which lies the Observable collection of shipmethods I am after. When I use ItemSource to attempt to point to the AllowableShipMethods collection, I get the error message "Cannot resolve property 'AllowableShipMethods' in datacontext of OrderEntryViewModel.
Data Context of User Control in which the grid is placed:
<UserControl.DataContext>
<!-- Declaratively create an instance of our OrderEntryViewModel -->
<local:OrderEntryViewModel />
</UserControl.DataContext>
I am checking if this is still an issue for you.
If you require any further assistance, please do not hesitate to ask.
Hi Lloyd,
I have modified the sample that I had attached before so that I included a UserControl in the MainWindow. I have used similar approach to bind the source of the XamComboEditor using the DataContext:
<Setter Property="ItemsSource" Value="{Binding DataItem.AllowableShipMethods}"/>
The binding of the XamDataGrid is changed so that the grid binds not to the whole OrderEntryViewModel but for the VmCartLineItems that returns a collection of LineItemsViewModel items.
If you have any other questions, please do not hesitate to ask.