Binding ObjectDataProvider to a property instead of a method

Suppose you have the following class:

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

I can use GetMethodto bind a method ObjectDataProviderto a method GetProcesses():

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

My question is, can I also be attached to a property Active?

If it turns out that I can do the following:

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

But for some reason this does not seem right.

Is there a cleaner way or a “correct” way to access a property instead of calling a method?

+3
source share
2 answers

You do not need to bind to a property, just bind to an object and use the Path to access the property

<ObjectDataProvider x:Key="pList"
                    ObjectType="{x:Type local:ProcessController}"/>
+8
source

, gcores, , , .

+9

Source: https://habr.com/ru/post/1706854/


All Articles