Xceed WPF Datagrid Binding?

Posts   
 
    
Posts: 34
Joined: 08-Nov-2007
# Posted on: 14-Feb-2008 10:35:22   

Anyone manage to bind a entity collection to Xceed WPF DataGrid. I either get value isn't of correct type of it just hangs in loading state, even something simple like this:

EntityCollection<PersonEntity> people = new EntityCollection<PersonEntity>(); this.PeopleGrid.ItemsSource = people;

Posts: 34
Joined: 08-Nov-2007
# Posted on: 14-Feb-2008 10:47:19   

Ignore the bit about it hang, it ALWAYS shows "value isn't of correct type", I tried self service, adapter, a WPF win app, a WPF xbap, regenerating, clean projects everything... even wrapper in entityview, it seems whenever the collection or underlying is an LLBLGen I can't bind to Xceed WPF Datagrid. If I manually loop over the entitycollection and add them to a normal List<> then it works, however I want to insertion support etc.. I hope its something that I can fix as failing that it's buggy Infragistics.

SD.LLBLGen.Pro.ORMSupportClasses.EntityViewBase`1.System.Collections.IList.Contains(Objec value)\r\n at System.Windows.Data.BindingListCollectionView.Contains(Object item)\r\n at System.Windows.Controls.ItemCollection.Contains(Object containItem)\r\n at Xceed.Wpf.DataGrid.DataGridControl.OnItemsChanged(NotifyCollectionChangedEventArgs e)\r\n at System.Windows.Controls.ItemsControl.OnItemCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)\r\n at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)\r\n at System.Windows.Data.CollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs args)\r\n at System.Windows.Controls.ItemCollection.System.Windows.IWeakEventListener.ReceiveWeakEvent(Type managerType, Object sender, EventArgs e)\r\n at System.Windows.WeakEventManager.DeliverEventToList(Object sender, EventArgs args, ListenerList list)\r\n at System.Windows.WeakEventManager.DeliverEvent(Object sender, EventArgs args)\r\n at System.Collections.Specialized.CollectionChangedEventManager.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args)\r\n at System.Windows.Data.CollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs args)\r\n at System.Windows.Data.BindingListCollectionView.RefreshOverride()\r\n at System.Windows.Data.CollectionView.Refresh()\r\n at System.Windows.Data.CollectionView.EndDefer()\r\n at System.Windows.Data.CollectionView.DeferHelper.Dispose()\r\n at System.Windows.Controls.ItemCollection.SetCollectionView(CollectionView view)\r\n at System.Windows.Controls.ItemCollection.SetItemsSource(IEnumerable value)\r\n at System.Windows.Controls.ItemsControl.OnItemsSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)\r\n at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)\r\n at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)\r\n at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)\r\n at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, OperationType operationType)\r\n at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, OperationType operationType, Boolean isInternal)\r\n at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)\r\n at System.Windows.Controls.ItemsControl.set_ItemsSource(IEnumerable value)\r\n at QuotationClient.Page1..ctor() in C:\\DevRoot\\Development\\VistaPlatform\\QuotationClient\\QuotationClient\\Page1.xaml.cs:line 32"

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 14-Feb-2008 10:48:37   

There is a XAML example in the following thread: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=12448

And yet the following thread suggest you use the code behind: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=10014

Posts: 34
Joined: 08-Nov-2007
# Posted on: 14-Feb-2008 11:11:25   

Thanks Walaa,

However Im not sure what you're suggestion as the examples relate the other binding scenarios, I've read through those threads and its seems Frans is suggesting that we're populuting the entitycollection with stuff it shouldnt be hence causing casting issues, however mine is an empty collection, not inherited, not modified, clean:

Brand new WPF application, Page1.xaml, with Xceed WPF free xpress datagrid:

        EntityCollection<TestEntity> people = new EntityCollection<TestEntity>();
        this.TemplateGrid.ItemsSource = people;

And I get "{"value isn't of the correct type."}"

Much appreciated!

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 14-Feb-2008 11:21:00   

Try to bind to the DefaultView.

EntityCollection<TestEntity> people = new EntityCollection<TestEntity>();
this.TemplateGrid.ItemsSource = people.DefaultView;
Posts: 34
Joined: 08-Nov-2007
# Posted on: 14-Feb-2008 11:26:41   

Hi Walaa,

Binding to DefaultView produces the same exception of "value isn't of the correct type."

Posts: 34
Joined: 08-Nov-2007
# Posted on: 14-Feb-2008 11:47:07   

The only way I can get LLBLgen to work with WPF is if I upgrade the client app to .Net 3.5 and do the following:

EntityCollection<PersonEntity> people = new EntityCollection<PersonEntity>(); TemplateGrid.ItemsSource = people.ToList<PersonEntity>() ;

However this removes 'Add' capability from the collection and be a big pain to deploy due to the upgrades requires.

Posts: 34
Joined: 08-Nov-2007
# Posted on: 14-Feb-2008 11:59:30   

Just to clarify. The other thread talks about null value when comparing... Not sure what it all means but the following still causes the same issue

1) FAILS

EntityCollection<PersonEntity> people = new EntityCollection<PersonEntity>(); PersonEntity person = new PersonEntity(); person.SetNewFieldValue("PersonId", null); people.Add(person); this.TemplateGrid.ItemsSource = people;

2) FAILS

EntityCollection<PersonEntity> people = new EntityCollection<PersonEntity>(); this.TemplateGrid.ItemsSource = people;

3) FAILS

EntityCollection<PersonEntity> people = new EntityCollection<PersonEntity>(); this.TemplateGrid.ItemsSource = people.DefaultView;

4) FAILS

EntityCollection<PersonEntity> people = new EntityCollection<PersonEntity>(); PopulatePeopleCollection(people); // populate with 50 records from DB this.TemplateGrid.ItemsSource = people.DefaultView;

5) FAILS Entity changes etc.. I tried different entities with different PK styles and even the most basic entities

Posts: 34
Joined: 08-Nov-2007
# Posted on: 14-Feb-2008 12:19:17   

6) FAILS EntityCollection<PersonEntity> people = new EntityCollection<PersonEntity>(tFactory); IBindingList component = (IBindingList)(people.GetList()) ; this.TemplateGrid.ItemsSource = component;

7) FAILS Frans mentions something to do with EntityFactory in another thread however I think it may be out of scope on this one, anyways I try I try, I put breakpoints on all methods in factory and it's not being called so I think I can rule out entityfactory.

TestFactory tFactory = new TestFactory(); EntityCollection<PersonEntity> people = new EntityCollection<PersonEntity>(tFactory); this.TemplateGrid.ItemsSource = people ;

public class TestFactory : IEntityFactory2 
    {


        #region IEntityFactory2 Members

        public IEntity2 Create(IEntityFields2 fields)
        {
            throw new NotImplementedException();
        }

        public IEntity2 Create()
        {
            throw new NotImplementedException();
        }

        public IEntity2 CreateEntityFromEntityTypeValue(int entityTypeValue)
        {
            throw new NotImplementedException();
        }

        public IEntityFields2 CreateFields()
        {
            throw new NotImplementedException();
        }

        public IEntityFields2 CreateHierarchyFields()
        {
            throw new NotImplementedException();
        }

        public IEntityFactory2 GetEntityFactory(object[] fieldValues, Dictionary<string, int> entityFieldStartIndexesPerEntity)
        {
            throw new NotImplementedException();
        }

        public IPredicateExpression GetEntityTypeFilter(bool negate)
        {
            throw new NotImplementedException();
        }

        #endregion

        #region IEntityFactoryCore Members

        public IRelationCollection CreateHierarchyRelations()
        {
            throw new NotImplementedException();
        }

        public string ForEntityName
        {
            get { throw new NotImplementedException(); }
        }

        #endregion
    }
Posts: 34
Joined: 08-Nov-2007
# Posted on: 14-Feb-2008 12:21:38   

I fear LLBLGen might not be fully compatible with WPF especially considering rich collections without conversion to List/IList everywhere, I appreciate that SD might not agree with some of the data binding concepts present in WPF, but we have to accept that for rich client apps that aren't web based (ignoring xbap) WPF is the way forward in terms of .Net and Windows environment combo.

cry cry

Posts: 34
Joined: 08-Nov-2007
# Posted on: 14-Feb-2008 12:35:05   

10) FAILS

        EntityCollection<PersonEntity> people = new EntityCollection<PersonEntity>();
        this.TemplateGrid.ItemsSource  = people.GetList();
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39613
Joined: 17-Aug-2003
# Posted on: 14-Feb-2008 12:59:10   

In general: if something fails with a 3rd party grid, we can't help you, contact the 3rd party grid vendor FIRST. TEST everything with vanilla .NET controls if something fails. We can't nor will test our code with every control out there and take the blame if something fails.

Our code works OK in normal winforms. If you ran into a problem with normal winforms (NOT WPF), please start a separate thread.

Databinding is tricky. If inheritance is used with entities, you're out of luck: databinding can't deal with that. We try but you'll probably run into issues with grids. This is because grids tend to rely on the first row of the types of the columns to produce.

I know .NET doesn't come with a WPF grid (at least .NET 3.0 didn't). I also know WPF uses a different style of databinding but should support old-style databinding as well. The error you see occurs because the object passed in isn't castable to the type of the collection. So in your person example, the new object isn't of type Person or castable to Person. What's causing that... we've to check.

The thing is now: we need to have a proper reprocase. This should be reproducable with a normal listbox using WPF. Again, if a 3rd party grid fails, sorry, but we won't invest any more time in tracking down bugs in 3rd party controls, unless it's proven the fault is on our side because normal .NET controls also fail.

That said, I tried a little app on WPF. The value passed to the method is 'null'. I have NO IDEA why.

So I commented out the check and simply returned when null was passed in... it worked!

I'll prepare a new build of the runtime lib v2.5 for you to test.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39613
Joined: 17-Aug-2003
# Posted on: 14-Feb-2008 13:04:17   

Please use the attached runtime lib and tell us if this fixes things. (build 2.5.8.0214)


public Window1()
{
    InitializeComponent();

    LinqMetaData metaData = new LinqMetaData(new DataAccessAdapter());
    var q = from c in metaData.Customer
            select c;
    comboBox1.ItemsSource = q;
    comboBox1.DisplayMemberPath = "CompanyName";
}

(2.6 linq code, works as well with new build)

Frans Bouma | Lead developer LLBLGen Pro
Posts: 34
Joined: 08-Nov-2007
# Posted on: 14-Feb-2008 16:43:05   

I could kiss you simple_smile j/k

It works, my apologises about the drama, I was under a lot of pressure to move on this and wanted to keep LLBLGEN, now I can!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39613
Joined: 17-Aug-2003
# Posted on: 14-Feb-2008 17:12:40   

Glad you can move on with your project AND LLBLGen Pro smile No worries about the drama, those situations aren't fun to be in, so if we can help a person to get out of such a situation, the better simple_smile

Frans Bouma | Lead developer LLBLGen Pro