如何在列表框的每一行中添加按钮

时间:2018-01-24 11:59:27

标签: c# wpf xaml

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

// get the html
$html = file_get_html('<url>');

// loop through the required element
foreach($html->find('body') as $body){

// loop through the selected element
$lis = $body->find('li');

    foreach($lis as $li){
        // loop through li to get the required span
        $span = $li->find('span', 0);
        if(null !== $span){
            echo $span->innertext;
        }
     }
}

1 个答案:

答案 0 :(得分: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>