如何在列表框中的每一行添加按钮[关闭]

问题描述 投票:0回答:1

我想在ListBox XAML的每一行中添加按钮,但我不知道如何。有谁能够帮我?代码如下:

<ListBox Margin="5" DisplayMemberPath="Key" ItemsSource="{Binding WindowsLicenseKeys}" HorizontalAlignment="Stretch" SelectedItem="{Binding SelectedKey}" Style="{StaticResource ListBoxNonScrollable}">
     <ListBox.InputBindings>
         <KeyBinding Gesture="Delete" Key="Delete" Command="{Binding DataContext.RemoveKeyCommand, ElementName=dg_keys}"/>
     </ListBox.InputBindings>
</ListBox>
c# wpf xaml
1个回答
1
投票

试试下面的代码

<ListBox Margin="5" DisplayMemberPath="Key" ItemsSource="{Binding WindowsLicenseKeys}" HorizontalAlignment="Stretch" SelectedItem="{Binding SelectedKey}" Style="{StaticResource ListBoxNonScrollable}">
  <ListBox.ItemTemplate>
    <Grid>
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="50"></ColumnDefinition>
        <ColumnDefinition Width="*"></ColumnDefinition>
      </Grid.ColumnDefinitions>          
      <Button Content="Delete" Grid.Column="0" Command="{Binding DataContext.RemoveKeyCommand, ElementName=dg_keys}"></Button>         
    </Grid>
  </ListBox.ItemTemplate>
</ListBox>
© www.soinside.com 2019 - 2024. All rights reserved.