【问题标题】:Loading another userControl in wpf Ribbon Window when the we click on DataGrid row当我们单击 DataGrid 行时,在 wpf 功能区窗口中加载另一个用户控件
【发布时间】:2012-06-04 18:57:13
【问题描述】:

请耐心阅读这篇文章...简要地说,我想要的是“当我 单击 DataGrid 行,这些值必须显示在另一个 表单(此处为 userControl)..”

我正在使用一个 Wpf 功能区窗口。该窗口分为两行。在第一行中,我填充了 Wpf 功能区,在第二行中,我填充了一个 Dock 面板以根据操作填充用户控件..

功能区有两个按钮

  1. 显示所有员工
  2. 添加员工

我创建了两个 Usercontrol Forms 一个是输入员工详细信息,第二个是显示 DataGrid 中的所有记录..

现在我首先单击 Ribbon Button1 以显示所有员工详细信息,然后将 userControl "CtlGridDisplay" 加载到 DockPanel(位于 Ribbon 窗口中)并在 DataGrid 中显示所有详细信息。

现在我双击行并获取选定的行employeeId 然后我希望在另一个用户控件“CtlAddEmployee”中显示该详细信息并且此用户控件必须仅显示在该 DockPanel 中.. 为此我试图清除 Dockpanel并为控件“CtlAddEmployee”创建了对象并将该控件添加到 DockPanel.. 但 DockPanel 仍然填充 仅 DataGRid 即填充“CtlGridDisplay”...我不明白为什么...

为此,我还使用了事件和委托,它可以很好地执行所有代码,但 Dockpanel 没有被清除,也没有加载新控件。..

但是当我单击一个功能区按钮 1 时,它会加载“CtlGridDisplay”,当我单击功能区按钮 2 时,它会在 Dock 面板中很好地加载“CtlAddEmployee”...

但是当我尝试显示数据时,我在一个用户控件中单击 DataGrid 以显示在另一个控件中不起作用..

Events Delegate 方法代码如下...

在用户控件“CtlDisplayEmployeeList”中的代码是

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);
            } 
        }
    }
}

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

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);    
    }
}

在另一个用户控件中..

构造函数...

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

当我调试所有代码时,所有代码都被很好地触发,但“CtlAddEmployee”表单没有加载到 DockPanel...Dock 面板仍然使用该 DataGRid...我不知道为什么请告诉我解决方案...。 .

感谢您的耐心等待...阅读本文...

【问题讨论】:

    标签: c# .net wpf oop events


    【解决方案1】:

    您也必须为停靠面板调用事件。例如 leftMouseButtonUp 和停靠你的用户控件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-25
      • 1970-01-01
      • 2023-03-28
      • 2011-06-04
      相关资源
      最近更新 更多