3

Suppose you have following class:

class ProcessController
{
    public List<Process> Active { get { ... } }
    ...
    public List<Process> GetProcesses() { ... }
}

I can use the GetMethod to bind a ObjectDataProvider to the GetProcesses() method:

<ObjectDataProvider x:Key="pList"
                    MethodName="GetProcesses"
                    ObjectType="{x:Type local:ProcessController}"/>

My question is, can I also bind to the property Active?

If found out that I can do the following:

<ObjectDataProvider x:Key="pList"
                    MethodName="get_Active"
                    ObjectType="{x:Type local:ProcessController}"/>

But somehow this doesn't feel right.

Is there some cleaner way or "right" way to access a property instead of invoking a method?

Theo Lenndorff
  • 4,556
  • 3
  • 28
  • 43

2 Answers2

9

The answer given by gcores will not work if the property is static, only if it is an instance member.

Jan
  • 3,825
  • 3
  • 31
  • 51
joe.feser
  • 439
  • 3
  • 10
8

You don't need to bind to a property, just bind to the object and use the Path to access the property

<ObjectDataProvider x:Key="pList"
                    ObjectType="{x:Type local:ProcessController}"/>
gcores
  • 12,376
  • 2
  • 49
  • 45