The operation columns of the WPF DataGrid are similar to LinkButton and wpflinkbutton.

Source: Internet
Author: User
Tags wpf datagrid

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.