Joel Martinez
Joel Martinez

Reputation: 47749

Button in a WPF ListItem

I'm a bit new to WPF. I am working on a list UI where each item in the list will have a set of corresponding buttons to operate on that particular data item.

Coming from a web background, I normally would have bound the value into a hidden element in that particular list item or something. However, I just need to find the corresponding technique in this WPF world :-)

Upvotes: 1

Views: 957

Answers (1)

Piotr Justyna
Piotr Justyna

Reputation: 4966

The most common technique is to use templates. Please consider using my example of a templated ListItem (for example ListBoxItem):

   <ListBox>
        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal">
                    <Button Command="{Binding Path=YourCommand}" Content="Dynamic Button 1" />
                    <Button Command="{Binding Path=YourSecondCommand}" Content="Dynamic Button 2" />
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>

Please feel free to ask if you have any questions/ideas.

Upvotes: 2

Related Questions