Search code examples
c#listviewnestedviewcontrollerxaf

Simpler alternative for accessing master object from nested listview on XAF


I want to know if there is simple and clear method other than this for accessing master object from a nested listview controller.

((PropertyCollectionSource)((ListView)View).CollectionSource).MasterObject

Do I have to write this in everywhere where i need to access master object?

I think this is not an elegant way and looks so lame.


Solution

  • Not tested yet, but you can use the following ViewController descendant:

    public class NestedViewController : ViewController
    {
        protected PropertyCollectionSource PropertyCollectionSource
        {
            get
            {
                return View is ListView ? ((ListView)View).CollectionSource is PropertyCollectionSource ? ((ListView)View).CollectionSource as PropertyCollectionSource : null : null;
            }
        }
    
        protected object MasterObject
        {
            get
            {
                return PropertyCollectionSource != null ? PropertyCollectionSource.MasterObject : null;
            }
        }
    }