首页 > 解决方案 > WPF: How can I use tag for specifying button's action?

问题描述

I want to make a student's list

so I used ItemsControl and Stackpanel to print student's name

And there's a button next to student's name (as a label)

So what I want to do is when I click the button the student's name is removed from the list

Here's my ItemsControl codes:

<ItemsControl x:Name="input_list" Grid.Column="0">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <StackPanel/>
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Vertical">
                <StackPanel Orientation="Horizontal">
                    <Button Height="25" Width="25" Style="{StaticResource ReturnButton}">
                        <StackPanel>
                            <Image Source="/remove_button.png" RenderSize="15 15" Stretch="Fill"/>
                        </StackPanel>
                    </Button>
                    <Label Margin="5 0 0 0" Style="{StaticResource DefaultFont}" Content="{Binding StudentName}" FontSize="20" FontWeight="DemiBold"/>
                </StackPanel>
            </StackPanel>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

标签: wpfxaml

解决方案


推荐阅读