开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜