如何将按钮添加到数据网格的最后一行/新行? [英] How to add a button to the last/new row of a datagrid?

查看:80
本文介绍了如何将按钮添加到数据网格的最后一行/新行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示一个弹出窗口,通过在数据网格的最后一行添加按钮来帮助用户向数据网格添加新行。我想必须要为 newrow / addrow 模板设置某种 DataGridTemplateColumn 属性?

I would like to show a popup to help the users to add a new row to a datagrid, by adding a button in the last row of the datagrid. I figured there must be some sort of DataGridTemplateColumnproperty I have to set for the newrow/addrow template?

推荐答案

您可以做的就是为 DataGridRow编写样式,

What you can do is to write a style for "DataGridRow" as

这是工作示例

<Style x:Type="DataGridRow">
<Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type DataGridRow}">
                    <Grid Background="{TemplateBinding Background}">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="auto"/>
                        </Grid.ColumnDefinitions>
                        <ContentPresenter Grid.Column="0" />
                        <Button Visibility = "{Binding IsLastRow}"/>!--can set converter to convert boolean to visibilty as well.
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
</Style>

因此,绑定属性基本上检查了最后一行的逻辑。(我不确定wpf datagrid由

So the binded property basically check the logic of the last row.(I am not sure wpf datagrid by itself provides some kind of property like "IsLastRow" or not. But if not anytime you can write your own logic).

在ContentTemplate中,您可以定义按钮处理程序或命令,否则它本身会提供某种属性,例如是否提供 IsLastRow。对象。

In ContentTemplate you can define your button handler or command object.

这篇关于如何将按钮添加到数据网格的最后一行/新行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆