标签:
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,如有不妥之处望指正。
WPF DataGrid 操作列 类似 LinkButton
标签:
原文地址:http://www.cnblogs.com/wsk198726/p/5667608.html