开发者

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

开发者 https://www.devze.com 2023-01-09 06:57 出处:网络
This is my XAML: ItemsSource=\"{x:Static app:Health开发者_运维技巧CheckSystemCategoryLookup.All}

This is my XAML:

ItemsSource="{x:Static app:Health开发者_运维技巧CheckSystemCategoryLookup.All}

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


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


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

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号