程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> WPF DataGrid 操作列 類似 LinkButton,wpflinkbutton

WPF DataGrid 操作列 類似 LinkButton,wpflinkbutton

編輯:C#入門知識

WPF DataGrid 操作列 類似 LinkButton,wpflinkbutton


WPF中沒有類似LinkButton,所以只有運用Button及樣式來實現LinkButton。

DataGrid 操作列 實現 多個類似LinkButton按鈕:

 

具體實現代碼如下:

<DataGrid Name="dgData" IsReadOnly="true" AutoGenerateColumns="False"> <DataGrid.Columns> <DataGridTemplateColumn Header="操作"> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <Button Name="btnInput" Content="填單" 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="取消" 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> 前台代碼 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(); } } 後台代碼

剛開始接觸WPF,如有不妥之處望指正。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved