Let's say I've got a DataGrid bound to a collection of type AreaVM. AreaVM has a property called InitialSub of type Sub. The ItemsSource of the combobox is another collection of type Sub.
<wct:DataGrid x:Name="grid"
ItemsSource="{x:Bind ViewModel.Source, Mode=TwoWay}"
Margin="12"
FontSize="4"
AutoGenerateColumns="False"
GridLinesVisibility="None"
CanUserResizeColumns="True"
CanUserSortColumns="True"
SelectionMode="Extended"
IsReadOnly="False"
VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Auto">
<wct:DagaGridColumns>
<wct:DataGridComboBoxColumn Binding="{Binding InitialSub, Mode=TwoWay}" Tag="InitialSub"
Header="Initial Sub"
Width="220"
ItemsSource="{x:Bind ViewModel.SourceForSubsList}"
DisplayMemberPath="SubName"
</wct:DataGridComboBoxColumn>
</wct:DataGridColumns>
</wct:DataGrid>
Why do I get this error: "The ItemsSource elements do not contain a property InitialSub. Ensure that the binding path has been set correctly." Can anyone help?
The pertinent parts of the page's viewmodel are as follows:
public ObservableCollection<Sub> SourceForSubsList { get; set; }
public ObservableCollection<AreaVM> Source
{
get => _source;
set
{
_source = value;
}
}
The AreaVM contains all the properties for each row of the datagrid. One of these properties is InitialSub:
public Subfactor InitialSub
{
get => Model.InitialSub;
set
{
if (value != Model.InitialSub && value != null)
{
Model.InitialSub = value;
RaisePropertyChanged(nameof(InitialSub));
}
}
}
The DataGrid does load correctly if I don't include the ComboBox columns.
I changed the ComboBox XAML to this but I'm still getting the same error:
<wct:DataGridComboBoxColumn Binding="{Binding InitialSub, Mode=TwoWay}"
Header="Initial Sub"
Width="220"
DisplayMemberPath="SubName"
ItemsSource="{x:Bind ViewModel.SourceForSubsList}"
Visibility="{x:Bind ViewModel.ShowInitialCoreColumns, Mode=OneWay, Converter={StaticResource boolToVisConverter}}">
</wct:DataGridComboBoxColumn>
The SubName property is a string. It is like the DisplayMemberPath is being ignored though. I still get this: "The ItemsSource elements do not contain a property InitialSub. Ensure that the binding path has been set correctly."
InitialCoreFindingSubfactor
toItemsSource
, I could not reproduce your issue, could you mind share minimal reproducible example? – Nico Zhu - MSFTViewModel
contain SourceForSubsList field ? Could you show the your viewmodel? – Nico Zhu - MSFTDisplayMemberPath
direct to string property of Sub class. – Nico Zhu - MSFT