The operation columns of the WPF DataGrid are similar to LinkButton and wpflinkbutton.
There is no LinkButton in WPF, so only the Button and style are used to implement the LinkButton.
The DataGrid operation column implements multiple buttons similar to LinkButton:
The specific implementation code is as follows:
<DataGrid Name = "dgData" IsReadOnly = "true" AutoGenerateColumns = "False"> <DataGrid. columns> <maid Header = "operation"> <maid. cellTemplate> <DataTemplate> <StackPanel Orientation = "Horizontal"> <Button Name = "btnInput" Content = "fill in" Cursor = "Hand" Click = "btnInput_Click" Margin = "5, 0, 5, 0 "> <Button. template> <ControlTemplate TargetType = "Button"> <TextBlock TextDecorations = "Underline" Name = "btnInput"> <ContentPresenter/> </TextBlock> </ControlTemplate> </Button. template> <Button. style> <Style TargetType = "Button"> <Setter Property = "Foreground" Value = "Blue"/> <Style. triggers> <Trigger Property = "IsMouseOver" Value = "true"> <Setter Property = "Foreground" Value = "Red"/> </Trigger> </Style. triggers> </Style> </Button. style> </Button> <Button Name = "btnCancel" Content = "cancel" Cursor = "Hand" Click = "btnCancel_Click" Margin = "5, 0, 5, 0"> <Button. template> <ControlTemplate TargetType = "Button"> <TextBlock TextDecorations = "Underline" Name = "btnCancel"> <ContentPresenter/> </TextBlock> </ControlTemplate> </Button. template> <Button. style> <Style TargetType = "Button"> <Setter Property = "Foreground" Value = "Blue"/> <Style. triggers> <Trigger Property = "IsMouseOver" Value = "true"> <Setter Property = "Foreground" Value = "Red"/> </Trigger> </Style. triggers> </Style> </Button. style> </Button> </StackPanel> </DataTemplate> </DataGridTemplateColumn. cellTemplate> </DataGridTemplateColumn> </DataGrid. columns> </DataGrid>Front-end code private void btnInput_Click (object sender, RoutedEventArgs e) {DataRowView drv = this. dgData. CurrentItem as DataRowView; if (drv! = Null) {string ID = drv. row ["ID"]. toString () ;}} private void btnCancel_Click (object sender, RoutedEventArgs e) {DataRowView drv = this. dgData. currentItem as DataRowView; if (drv! = Null) {string ID = drv. Row ["ID"]. ToString ();}}Background code
I was just getting started with WPF. If anything is wrong, I hope I can correct it.