我的WPF应用程序中有一个DataGrid,其中的每一行都以Delete按钮结尾。
<DataTemplate>
<Button
Command="Delete"
CommandParameter="{Binding}" FontWeight="Bold" Foreground="{x:Null}" IsEnabled="True" BorderBrush="{x:Null}">
<Button.Background>
<ImageBrush ImageSource="Ikonok/bin.png"/>
</Button.Background>
<Button.Style>
<Style TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Background="{TemplateBinding Background}" BorderBrush="{x:Null}" BorderThickness="1">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Button.Style>
</Button> </DataTemplate>
我该如何在后面编写代码,以便在要求用户是否真的要删除该项目的删除操作之前放置一个MessageBox?
答案 0 :(得分:3)
当您触发“删除”按钮的事件时,请将此代码放在事件的开头。
MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Are you sure?", "Delete Confirmation", System.Windows.MessageBoxButton.YesNo);
if (messageBoxResult == MessageBoxResult.Yes)
{
//...
}
else
{
//...
}