I was wondering if someone could give a simple example of how to bind a an EntityView2 to a WPF ComboBox.
I have no problems binding to listviews or the xceed wpf datagrid but I have great difficulty binding to a combobox, getting the ambiguous error:
"value isn't of the correct type":
System.ArgumentException was unhandled
Message="value isn't of the correct type."
Source="SD.LLBLGen.Pro.ORMSupportClasses.NET20"
StackTrace:
at SD.LLBLGen.Pro.ORMSupportClasses.EntityViewBase`1.System.Collections.IList.IndexOf(Object value)
at System.Windows.Data.BindingListCollectionView.InternalIndexOf(Object item)
at System.Windows.Data.BindingListCollectionView.IndexOf(Object item)
at System.Windows.Controls.ItemCollection.IndexOf(Object item)
at System.Windows.Controls.ItemsControl.NavigateToItem(Object item, Int32 elementIndex, ItemNavigateArgs itemNavigateArgs, Boolean alwaysAtTopOfViewport)
at System.Windows.Controls.ComboBox.<OnIsDropDownOpenChanged>b__1(Object arg)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
at System.Windows.Threading.DispatcherOperation.InvokeImpl()
at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.ProcessQueue()
I assume the combobox is trying to find the index of a particular item within the collection, but instead of using the SelectedValuePath, it's attempting to pass in a string.
Snipets follow:
<UserControl.Resources>
<CollectionViewSource x:Key="cvsCountries" Source="{Binding Path=Countries}">
<CollectionViewSource.SortDescriptions>
<scm:SortDescription PropertyName="DisplayName" Direction="Ascending"/>
</CollectionViewSource.SortDescriptions>
</CollectionViewSource>
</UserControl.Resources>
<ComboBox x:Name="cmbPostalCountry" Grid.Row="4" Grid.Column="1" ItemsSource="{Binding Source={StaticResource cvsCountries}}" DisplayMemberPath="DisplayName" SelectedValuePath="IsoCode" SelectedValue="{Binding Path=PhysicalCountryIsoCode}" />
The DataContext of the view has been set to a ContactEntity
with one of it's properties being: PhysicalCountryIsoCode, which has a fk relationship with Country on IsoCode
Countries is an EntityView2 of CountryEntity which has the corresponding properties listed above:
DisplayName
IsoCode
Any help or suggestions, or even a simple example of an entity with an fk relationship being displayed within a combobox in wpf would be greatly appreciated.