【问题标题】:How to Load the UserControl in to Dockpanel Dynamically...in wpf如何在 wpf 中动态地将 UserControl 加载到 Dockpanel...
【发布时间】:2012-07-02 17:42:15
【问题描述】:

我使用的是RibbonWindow,在第一部分我使用的是 ribbonBar 按钮和其他控件,在第二部分我使用了DockPanel 显示/加载其他控件

我有两个用户控件,一个是使用TextBox显示详细信息 和DropDown 控件和另一个userControl 是显示所有 DataGrid 中的现有数据..

这两个控件必须根据 条件,在RibbonWindow...

现在,我想要的是当我点击任何 Grid 行时,我 需要将选定的 GridRow 数据填充到 DisplayUserControl (userControl1) 并且 userControl 必须加载(替换第二个 userControl) 到那个 DockPanel...

我所做的是……

首先我将UserControl2 加载到Dockpanel RibbonWindow 并填写 Grid 数据

我已经使用 ClickEvent 获取了网格行的值
(GridList_MouseDoubleClick())

在那个方法中,我调用了 One DelegateEvent 来调用该方法 在 MainRibbonWindow 中声明...

该方法应该显示DockPanel 并加载另一个用户控件。代码如下。

下面的方法在 MainRibbonWindow...

public void fnDisplayEmployeeDetails(string str,DockPanel dockPannel)
{
    //  dockPannel is to be cleared...
     this.Dispatcher.BeginInvoke((Action)delegate { dockPannel.Children.Clear(); }, null);  //To Clear the Dock Panel

    CtlAddEmployee frm2 = new CtlAddEmployee(str); //userControl1 and here str is Id of the Row...

    dockPannel.Children.Add(frm2);

}

这里所有的工作都完成了,但是DockPanel 仍然在 仅第二个用户控件(即仅显示网格)。坞站面板不 替换为 firstUserControl

如果我试图在另一个窗口中显示这些相同的值 Dockpanel,它显示正常。我不知道为什么这很奇怪 行为正在发生...

public void fnDisplayEmployeeDetails(string str,DockPanel docPannel)
{
    this.Dispatcher.BeginInvoke((Action)delegate { docPannel.Children.Clear(); }, null);  //To Clear the Dock Panel

    CtlAddEmployee frm2 = new CtlAddEmployee(str);
    MainWindow mnWindow = new MainWindow();    //another window Form...
    mnWindow.MainWindowDock.Children.Add(frm2);
    mnWindow.ShowDialog();  //here it is showing well....
}

我应该如何在另一个用户控件中显示网格值的详细信息,并且该用户控件必须填写在同一个 Dockpanel 中......

【问题讨论】:

    标签: wpf events delegates


    【解决方案1】:

    您是否尝试过不委托添加子控件?我发现当您从不同的线程访问 UI 组件时会发生这些行为。在不同窗口的情况下(第二个测试有效),由于新窗口是在该新线程中创建的,因此交互工作正常......

    【讨论】:

      猜你喜欢
      • 2012-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多