如何通过清除WPF中已经存在的控件来显示Dockpanel中的userControl [英] how to Dispaly the userControl in Dockpanel by clearing already exist Control in wpf

查看:159
本文介绍了如何通过清除WPF中已经存在的控件来显示Dockpanel中的userControl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

海,

我在第一部分中使用RibbonWindow.在第二部分中,我使用RibbonBar按钮和其他按钮,在第二部分中,我使用DockPanel显示/加载其他控件...以进行受尊敬的操作...

我有两个userControl,一个用于使用TextBox和DropDown控件显示详细信息,另一个userControl用于显示DataGrid中的所有现有数据.
这两个控件必须基于RibbonWindow中的Condition放置在该DockPanel中.

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

为此,我要做的是....

首先,我将UserControl2加载到RibbonWindow的Dockpanel中.并填充网格数据...

并且我已经使用ClickEvent获取了网格行的值-

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

该方法就像..下面清除Dockpanel并加载另一个userControl ...

下面的方法在MainRibbonWindow中...

Hai,

i am Using the RibbonWindow.. in that first section i am using ribbonBar buttons and others and in second section i used DockPanel to Show / Load the Other Controls...for respected actions...

i have Two userControls, one is to Display the Details using TextBox and DropDown Controls and Another userControl is to Show all the Existing Data in DataGrid..

these two controls have to be palced in that DockPanel based on Condition, which is in RibbonWindow...

Now,What i want here is, When i click on the any of the Grid row, i need to fill that selected GridRow Data into the Display userControl (userControl1) and that userControl have to load (replace the second userControl) into that DockPanel...

for that what i have Done is....

First i loaded the UserControl2 in to Dockpanel of the RibbonWindow..and fill the Grid Data...

and i have taken the Values of the Grid Row using the ClickEvent --

and in that Method i have called One DelegateEvent to call the Method declared in MainRibbonWindow...

that method is like..below to clear the Dockpanel and load another userControl...

the below method is in 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仅保留了第二个userControl(即,仅显示Grid ..).扩展坞面板未替换为fristUserControl ...

但是,如果iam试图在另一个FormWindow Dockpanel..it"中显示相同的值,则显示得很好...我不知道为什么会有这种奇怪的行为...


Here all the Work is Done well but the DockPanel Remains with the second userControl only(i.e Displaying Grid only..)..The dockpanel not replaced with the fristUserControl...

But if iam trying to dispaly those same values in Another FormWindow Dockpanel..it displaying well ...i don''t know why for this strange behaviour...

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....
}


请告诉我将Grid值的Details ..显示给另一个usercontrol ..的正确方法,并且必须在同一Dockpanel中填充该usercontrol ....

谢谢


please tell me the correct way to show the Details.. of the Grid values in to another usercontrol..and that usercontrol has to be filled in same Dockpanel....

Thank you

推荐答案

yourdockpanel.Children.Clear()





clears all childrens of dockpanel.


我需要通过传递类的旧对象引用(使用参数化构造函数)来引用该类的旧对象引用.而不是通过创建新的对象并调用它们来引用...
i need to refer the old object reference of the class by passing it(using parametrized constructors)..not by creating new one and calling them...


这篇关于如何通过清除WPF中已经存在的控件来显示Dockpanel中的userControl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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