tags:

views:

17

answers:

2

This is my XAML:

ItemsSource="{x:Static app:HealthCheckSystemCategoryLookup.All}

Is there a way to make HealthCheckSystemCategoryLookup.All a function instead of a property?

+1  A: 

No, x:Static can only handle enum members, properties, and fields. You can use ObjectDataProvider if you want to bind to the result of a method call. You would do something like this:

<Window.Resources>
    <ObjectDataProvider
        x:Key="Data"
        ObjectType="app:HealthCheckSystemCategoryLookup"
        MethodName="All"/>
</Window.Resources>
<ListBox ItemsSource="{Binding Source={StaticResource Data}}" />
Quartermeister
A: 

Why not just bind to a property which calls the method in its Getter.

public IEnumberable<object> Data
{
  get
  {
    return All();
  }
}
benPearce
What I'm binding to doesn't have property semantics. It can potentially fail or takes a long time to read. Repeated reads do not necessarily give the same result.
Jonathan Allen
Then maybe you need to extend this data provider, or put a wrapper around it to handle the errors, cache results, run it in a separate thread etc.
benPearce