码迷,mamicode.com
首页 > Windows程序 > 详细

WPF DataGrid 操作列 类似 LinkButton

时间:2016-07-13 20:31:53      阅读:974      评论:0      收藏:0      [点我收藏+]

标签:

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!