我想在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>
试试下面的代码
<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>