WPF DataGrid Action column is similar to LinkButton

Source: Internet
Author: User
Tags wpf datagrid

There is no similar linkbutton in WPF, so only the button and style are used to implement LinkButton.

The DataGrid Action column implements several similar LinkButton buttons:

The specific implementation code is as follows:

<datagrid name="Dgdata"isreadonly="true"autogeneratecolumns="False"> <DataGrid.Columns> <datagridtemplatecolumn header="Operation"> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <sta Ckpanel orientation="Horizontal"> <button name="Btninput"Content="Filling Order"Cursor="Hand"click="Btninput_click"margin="5,0,5,0"> <Button.Template> <controltemplate targettype="Button"> <textblock textdecorations="Underline"Name="Btninput"> <contentpresenter/> &LT;/TEXTB                            Lock> </ControlTemplate> </Button.Template> <Button.Style> <style targettype="Button"> <setter property="Foreground"Value="Blue"/> <Style.Triggers> <trigger Propert y="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 Propert y="IsMouseOver"Value="true"> <setter property="Foreground"Value="Red"/> </Trigger> </Style.Triggers> </Style> </Button.Style> </ button> </StackPanel> </DataTemplate> </datagridtemplatecol Umn. Celltemplate> </DataGridTemplateColumn> </DataGrid.Columns></DataGrid>
Front Code
Private voidBtninput_click (Objectsender, RoutedEventArgs e) {DataRowView DRV= This. Dgdata.currentitem asDataRowView; if(DRV! =NULL)    {        stringID = DRV. row["ID"].    ToString (); }}Private voidBtncancel_click (Objectsender, RoutedEventArgs e) {DataRowView DRV= This. Dgdata.currentitem asDataRowView; if(DRV! =NULL)    {        stringID = DRV. row["ID"].    ToString (); }}
Background Code

Just start contacting WPF, if there's something wrong with it.

WPF DataGrid Action column is similar to LinkButton

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.