Jonathan Allen
Jonathan Allen

Reputation: 70327

WPF/XAML: Is there a way to use x:static with a function?

This is my XAML:

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

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

Upvotes: 2

Views: 815

Answers (2)

benPearce
benPearce

Reputation: 38353

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

public IEnumberable<object> Data
{
  get
  {
    return All();
  }
}

Upvotes: 1

Quartermeister
Quartermeister

Reputation: 59149

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}}" />

Upvotes: 3

Related Questions