当我们点击DataGrid行时,在wpf Ribbon窗口中加载另一个userControl [英] Loading another userControl in wpf Ribbon Window when the we click on DataGrid row

查看:152
本文介绍了当我们点击DataGrid行时,在wpf Ribbon窗口中加载另一个userControl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请耐心阅读这个...简短的我想要的是当我
点击DataGrid行这些值必须显示在另一个
表单(这里是userControl)..

please be patience to read this... briefly what i want is " when i click on the DataGrid row those values have to be displayed in another form(here userControl).."

我正在使用一个Wpf功能区窗口。该窗口分为两行。在第一行我填充Wpf功能区,在第二行我填充一个Dock面板,以填充UserControls基于Action ..

I am using one Wpf Ribbon window.. And that window is divided in to two rows. In first row i filled with Wpf Ribbon and in Second row i filled one Dock panel to fill the Usercontrols based on the Action..

功能区有两个按钮


  1. 显示所有员工

  2. 添加员工

我创建了两个用户控制表单,一个是输入员工详细信息,第二个是显示DataGrid中的所有记录。

I created two Usercontrol Forms one is to enter the employee Details , second one is to Display all the Records in DataGrid..

现在我首先点击功能区Button1显示所有员工详细信息,然后将userControlCtlGridDisplay加载到DockPanel(在Ribbon窗口中),并显示DataGrid中的所有详细信息。

Now i First Click on Ribbon Button1 to Display all the Employee Details ,then userControl "CtlGridDisplay "is loaded in to the DockPanel(which is in Ribbon Window) and displaying the all the Details in DataGrid.

现在我双击行并选择一行employeeId然后我希望在另一个用户控件CtlAddEmployee中显示该详细信息,并且该userControl必须在该DockPanel中显示..因为我试图清除Dockpanel并为控件CtlAddEmployee创建了对象,并将该控件添加到DockPane但是DockPanel仍然填充
DataGRid只是填充CtlGridDisplay...我不明白为什么...

Now i Double Click on row and take the selected row employeeId And then i wish to Display that Details in Another Usercontrol "CtlAddEmployee" And this userControl has to be Displayed in that DockPanel only.. for that i trying to Clear the Dockpanel and created the object for the Control "CtlAddEmployee" and added that control to the DockPanel.. But the DockPanel Remains fill with DataGRid only i.e filled with "CtlGridDisplay" ... i can't understand why...

要做这个我也使用了事件和代表,它执行所有的代码很好,但是Dockpanel没有被清除,没有加载新的控件..

To do this i have also used the Events and Delegates ,it executes all the code well but the Dockpanel is not cleared and didn't loaded with new control..

但是当我点击一个功能区按钮1它加载CtlGridDisplay,当我点击功能区按钮2,它在Dock面板中加载CtlAddEmployee...

But when i click one ribbon button1 it loads the "CtlGridDisplay" and when i click on Ribbon button2, its loading "CtlAddEmployee" in Dock panel well...

但是当我试图显示数据我在一个userControl中点击DataGrid显示在另一个控件中不起作用。

but when i trying to display the Data what i have click on DataGrid in one userControl to display in Another control doesn't Work..

事件代理方法代码如下...

Events Delegate approach Code is like below...

在用户控件CtlDisplayEmployeeList中,代码​​是

In User Control "CtlDisplayEmployeeList " the Code is

public event MyOrganizationDetails.MainRibbonWinodw.DisplayEmployeeHandler DisplayemployeeEvent;

private void GridList_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
    MainRibbonWinodw mainRibbonobj = new MainRibbonWinodw();
    this.DisplayemployeeEvent += new MainRibbonWinodw.DisplayEmployeeHandler(mainRibbonobj.fnDisplayEmployeeDetails);
    if (GridList.SelectionUnit == DataGridSelectionUnit.FullRow)
    {
        if (GridList.SelectedItems.Count > 0)
        {
            for (int i = 0; i < GridList.SelectedItems.Count; i++)
            {
                DataGrid dg = sender as DataGrid;
                EmployeeDetail detail = dg.SelectedItem as EmployeeDetail;
                string selectedEmp = detail.EmpId; //it gives Employee Id

                if (DisplayemployeeEvent != null)
                    DisplayemployeeEvent(selectedEmp);
            } 
        }
    }
}

功能区窗口..代码将...处理这里的事件...

In Ribbon Window.. the Code will be... which handles the Event here...

public partial class MainRibbonWinodw : RibbonWindow
{
    public delegate void DisplayEmployeeHandler(string str);

    public void fnDisplayEmployeeDetails(string str)
    {
        CtlAddEmployee frm2 = new CtlAddEmployee(str);
        DockPanelInRibbon.Children.Clear();
        DockPanelInRibbon.Children.Add(frm2);    
    }
}

另一个User Control ..

In another User Control..

构造函数...

public CtlAddEmployee(string str)
{
    InitializeComponent();
    fnDisplayingEmployee(str);
}

当我调试所有代码被触发得很好,但CtlAddEmployee形式不是加载到DockPanel ... Dock Panel仍然与DataGRid ...我不知道为什么请告诉我解决方案.....

when i debugging all the Code is fired well but "CtlAddEmployee" form is not loaded to DockPanel... the Dock panel remains with that DataGRid... i Don't know why please tell me the solution .....

谢谢你的耐心...读这个...

Thank you for your patience...to read this...

推荐答案

你也必须打电话给dockpanel事件。例如leftMouseButtonUp,然后停止您的用户控制。

You must call event for dockpanel too. For example leftMouseButtonUp and there dock yours usercontrol.

这篇关于当我们点击DataGrid行时,在wpf Ribbon窗口中加载另一个userControl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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