带编辑按钮的WPF数据网格 [英] WPF datagrid with edit button

查看:70
本文介绍了带编辑按钮的WPF数据网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个DataGrid ,该列表由使用DataGrid.DataContext = list
的列表填充
我的问题是我需要在单独的WPF窗口中编辑这些值.我读过很多关于嵌入式编辑的文章,但是从另一个窗口填充表格的知识却很少.

编辑窗口将具有确定"和取消"按钮,并且仅应在确定"命令上将更改镜像到数据网格.辅助窗口也应填充所选行的值.到目前为止,如有必要,可以提供代码.

I currently have a DataGrid which is populated by a list using DataGrid.DataContext = list

My issue is that i need to edit these values in a seperate WPF window. I''ve read many articles about in-line editing, but not much on populating the table from another window.

The edit window will have OK and Cancel buttons, and should only mirror the changes back to the datagrid on the OK command. The secondary window should also be populated with the selected row''s values. Can provide code so far if necessary.

推荐答案

我希望您的主窗口包含DataGrid.
创建数据模板
i hope your main window contain DataGrid .
create a datatemplate
<datatemplate x:key="DataTemplateBaseChargeSetting" xmlns:x="#unknown">
                <border borderthickness="1">
                          BorderBrush="Transparent"
                          CornerRadius="2"                          
                          HorizontalAlignment="Stretch"
                          Margin="2">                   
                    
                    <border borderbrush="Black">
                            BorderThickness="1"
                            CornerRadius="3"
                            Margin="2">
                        <grid>
                        <grid.columndefinitions>
                            <columndefinition width="auto" />
                            <columndefinition width="auto" />
                            <columndefinition width="*" />
                        </grid.columndefinitions>
                        
                        <uielements:gibutton name="btnEdit" xmlns:uielements="#unknown">
                                             Grid.Column="0"
                                             Margin="2"
                                             Height="18"
                                             Width="18"
                                             Command="LocalCommands:Commands.EditBaseRate"
                                             CommandParameter="{Binding}"
                                             VerticalAlignment="Center"
                                             HorizontalAlignment="Stretch"
                                             HorizontalContentAlignment="Stretch"
                                             Style="{DynamicResource IconButtonStyle}">
                            <image source="{DynamicResource Edit}">
                                   VerticalAlignment="Center"
                                   HorizontalAlignment="Center"
                                   Height="18"
                                   Width="18"></image>
                        </uielements:gibutton>
                        <uielements:gibutton name="btnDelete" xmlns:uielements="#unknown">
                                             Width="18"
                                             Height="18"
                                             Style="{StaticResource IconButtonStyle}"
                                             HorizontalAlignment="Stretch"
                                             HorizontalContentAlignment="Stretch"
                                             VerticalAlignment="Center"
                                             Grid.Column="1"
                                             Margin="2"
                                             Command="LocalCommands:Commands.DeleteBaseRate"
                                             CommandParameter="{Binding}">
                            <image source="{DynamicResource Delete}">
                                   VerticalAlignment="Center"
                                   HorizontalAlignment="Center"
                                   Height="22"
                                   Width="22" />
                        </image></uielements:gibutton>
                        <textblock name="tblChargeCategory">
                                    Margin="2" Width="150"
                                    HorizontalAlignment="Stretch"
                                    Text="{Binding Path=CHARGE_CATEGORY}"
                                    TextTrimming="CharacterEllipsis"
                                    ToolTip="{Binding Text}"
                                    Grid.Column="2" />
                    </textblock></grid>
                        </border>
                </border>
            </datatemplate>




在弹出窗口之后,您应该创建一个名为SelectedItem的clr属性.




behind the popup window u should create a clr property named as SelectedItem .

private DataRowView _selectedItem;
public DataRowView SelectedItem
{
    get
    {
        return _selectedItem;
    }
    set
    {
        _selectedItem = value;
        OnPropertyChanged("SelectedItem");
    }
}



在编辑按钮上单击事件
呼叫弹出窗口

并创建弹出窗口的对象并调用其属性,并将选定的行分配给该属性



on edit button click event
call pop window

and create object of pop window and call their property and assign the selected row to that property


这篇关于带编辑按钮的WPF数据网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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