开发者

Binding to "this" for itemsource?

开发者 https://www.devze.com 2023-03-09 02:17 出处:网络
Say I have a listbox, whose itemsource is bound to a Collection of classes Foo How can I xaml bind a property directly to t开发者_如何学编程he instance of Foo?

Say I have a listbox, whose itemsource is bound to a Collection of classes Foo

How can I xaml bind a property directly to t开发者_如何学编程he instance of Foo?

The property I want to bind is the source of an Image, and the Foo class has several properties that influence the source, so in my Converter class. I want Foo


If you mean that you have the ItemsSource property of an ListBox bound to the collection (you don't bind to controls, but to their properties), and you want to show an image for each Foo in the collection, you can do it like this:

<ListBox ItemsSource="{Binding whatever}">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <Image Source="{Binding Converter={StaticResource converter}}" />
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

Just by leaving the binding's path empty, it is set to the current item.

0

精彩评论

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